timber101

timerno5

Aug 18th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from time import sleep
  2.  
  3. def countdown(t):
  4.     print("counting down")
  5.  
  6.     while t > 0:
  7.         t2 = t # this preserves the countdown timer
  8.         dayz = t2 // (24 * 3600) # captures the no of days
  9.         t2 = t2 % (24 * 3600) # removes no of days from seconds
  10.         hourz = t2 // 3600 # captures no of hours
  11.         t2 %= 3600 # removes no of hours from seconds
  12.         minutez = t2 // 60 # captures no of minutes
  13.         secondz = t2 % 60 # removes no of minutes in seconds
  14.         print("d:h:m:s-> %d:%d:%d:%d" % (dayz, hourz, minutez, secondz)) # %d is a placeholder for the follwoing 4 values
  15.         sleep(1)
  16.         t = t -1 # could write this as t -= t
  17.  
  18. tgttimer = float(input("enter timer in seconds: ") )
  19.  
  20. countdown(tgttimer)
  21.  
  22. print("Times Up!")
Add Comment
Please, Sign In to add comment