Premium Only Content

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.
-
19:01
Russell Brand
13 hours agoTheo Von Just SHOCKED EVERYBODY With His Take on Trump Tariffs
94K107 -
14:22
Tundra Tactical
7 hours ago $5.07 earnedTRUMP DOJ Decides CZ Scorpion Is A Decepticon.
43.3K14 -
4:53:37
Culturama Podcast
5 hours ago $3.62 earnedEaster Special! Hollow Knight Stream!
33.3K4 -
1:04:29
Sarah Westall
8 hours agoThe Philippines and Massive Stores of Gold for all the People of the World w/ Joseph Allain
57.1K43 -
17:23
Exploring With Nug
17 hours ago $7.36 earnedCorvette Found Underwater! Continuing The Search For Laresha Walker!
50K2 -
3:06:31
Damysus Gaming
5 hours agoWeaving into the Deep South: South of Midnight First Play! Part 2
10.6K2 -
24:55
MYLUNCHBREAK CHANNEL PAGE
13 hours agoDams Destroyed China
70.6K43 -
5:44:44
BigTallRedneck
6 hours agoFORTNITE - THE QUEST FOR THE OPAL PICKLE
10.9K3 -
7:05:52
Razeo
9 hours agoEpisode 3: 1st playthrough - Mandragora. What happens when The Pancake King goes eats Waffles?
9.27K -
1:45:48
Joker Effect
6 hours agoWHY IS EVERYONE SO ANGRY?! Just play on Motherland and have fun! Enjoy life!
7.86K1