I’ve basically made an alarm without using the playsound
library, and the timer is not working properly. I used ANSI escape codes, but they messed up the timer.
import time
Clear = "33[2J"
Clear_and_return = "33[H"
def alarm(seconds):
time_elapsed = 0
print(Clear)
while time_elapsed < seconds:
time.sleep(1)
time_elapsed += 1
time_left = seconds - time_elapsed
min_left = time_left // 60
sec_left = time_left % 60
print(f"{Clear_and_return} Time left till alarm: {min_left:02d}:{sec_left:02d}")
minutes = int(input("Minutes: "))
seconds = int(input("Seconds: "))
alarm(minutes * 60 + seconds)
The program runs without errors, but the timer doesn’t show up until it reaches 00:00.
New contributor
A A T H I is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.