fork download
  1. import time
  2.  
  3. def hour_timer():
  4. total_seconds = 60 * 60 # 1 hour in seconds
  5.  
  6. try:
  7. for remaining in range(total_seconds, 0, -1):
  8. mins, secs = divmod(remaining, 60)
  9. time_format = '{:02d}:{:02d}'.format(mins, secs)
  10. print(f"Time left: {time_format}", end='\r')
  11. print("\nTime's up! 1 hour has passed.")
  12. except KeyboardInterrupt:
  13. print("\nTimer interrupted by user.")
  14.  
  15. if __name__ == "__main__":
  16. hour_timer()
  17.  
Success #stdin #stdout 0.03s 25440KB
stdin
Standard input is empty
stdout
import time

def hour_timer():
    total_seconds = 60 * 60  # 1 hour in seconds

    try:
        for remaining in range(total_seconds, 0, -1):
            mins, secs = divmod(remaining, 60)
            time_format = '{:02d}:{:02d}'.format(mins, secs)
            print(f"Time left: {time_format}", end='\r')
            time.sleep(1)
        print("\nTime's up! 1 hour has passed.")
    except KeyboardInterrupt:
        print("\nTimer interrupted by user.")

if __name__ == "__main__":
    hour_timer()