2

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 = "\033[2J"
Clear_and_return = "\033[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.

1
  • 2
    I can't replicate the problem. What OS are you working on? What terminal are you using? Commented Aug 6, 2024 at 2:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.