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.
-
LIVE
LumpyPotatoX2
3 hours ago$10,000 PUBG Tournament w/GamersError - #RumbleTakeover
185 watching -
3:22
One Bite Pizza Reviews
1 day agoBarstool Pizza Review - Marco Pizzeria & Restaurant (Branford, CT)
4.44K16 -
41:46
Standpoint with Gabe Groisman
8 hours agoEp. 27. From GameStop to the NBA. Gabe Plotkin
2.93K -
55:04
Matt Kohrs
5 hours agoThe Volatile Week Ahead || The MK Show
14.2K10 -
26:18
Stephen Gardner
4 hours agoTop Republican UNLOADS on Democrats and Biden's MENTAL HEALTH!!
22.2K54 -
44:30
Michael Franzese
2 days agoCancel Culture Backlash of My UK Tour | Michael Franzese
79.5K47 -
35:12
Island Hopper TV
1 day agoFull Costa Rica Travel Guide 2024
39.1K32 -
4:43
ParisDemers
1 day agoThis Diet Hack Changed My Life! (How To Get Ripped FAST!)
54.6K46 -
46:57
Crime Circus
1 day agoApple River ST*BBING!! Stand Your Ground Interrogation of Man in Wisconsin
62.6K45 -
9:39
Tactical Advisor
1 day agoHow To Improve Your Shooting For FREE! Mantis Blackbeard X
77.8K14