Countdown Timer Using Function In Python-Free Python Course
In this project, we will be using the time module and its sleep() function. Follow the below steps to create a countdown timer:
Step 1: Import the time module.
Step 2: Then ask the user to input the length of the countdown in seconds.
Step 3: This value is sent as a parameter 't' to the user-defined function countdown(). Any variable read using the input function is a string. So, convert this parameter to 'int' as it is of string type.
Step 4: In this function, a while loop runs until time becomes 0.
Step 5: Use divmod() to calculate the number of minutes and seconds. You can read more about it here.
Step 6: Now print the minutes and seconds on the screen using the variable timeformat.
Step 7: Using end = '\r' we force the cursor to go back to the start of the screen (carriage return) so that the next line printed will overwrite the previous one.
Step 8: The time.sleep() is used to make the code wait for one sec.
Step 9: Now decrement time so that the while loop can converge.
Step 10: After the completion of the loop, we will print "Fire in the hole" to signify the end of the countdown.
-
40:51
World Nomac
16 hours ago72 Hours in Kyoto and Osaka Japan
8.35K2 -
14:19
Degenerate Jay
1 day agoShould Solid Snake Ever Get Another Metal Gear Solid Game?
11.6K4 -
48:46
The Lou Holtz Show
15 hours agoThe Lou Holtz Show Ep 17 | Linda McMahon on WWE, Small Business, and Leadership #podcast
7.29K2 -
1:35:09
Atlantic Underground Podcast
1 day agoGoogle Eyed Monster a Whistleblower Story
9.1K1 -
LIVE
Right Side Broadcasting Network
4 days agoLIVE REPLAY: President Trump Holds a Rally in Indiana, Pennsylvania - 9/23/24
4,997 watching -
3:11:25
The Quartering
13 hours agoTrump Rally Post Show, Kamala Harris Desperation, Diddy Mess Gets Worse & WW3
160K81 -
1:40:45
Fresh and Fit
12 hours agoHow To Make Money Streaming
95.4K33 -
1:37:28
Kim Iversen
15 hours agoNOT GUILTY: The Uhuru Three Are Cleared Of Being Russian Agents in Landmark Free Speech Case
137K122 -
2:30:03
We Like Shooting
23 hours ago $2.74 earnedWe Like Shooting 577 (Gun Podcast)
55.6K1 -
1:00:18
Flyover Conservatives
1 day agoIs Kamala Harris China’s Trojan Horse for America’s Fall? - Trevor Loudon; The Economic Warning Signs You Can’t Ignore - Dr. Kirk Elliott | FOC Show
88K19