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.
-
4:30
Caleb Hammer
1 month ago27 Year Old Doesn't Give A Single Crap About His Finances
10.6K24 -
52:38
Squaring The Circle w/ Randall Carlson
5 hours ago#011 The Cosmos Speaks: The Tunguska Impact Event Pt.2 - Squaring The Circle
7794 -
27:47
Degenerate Jay
6 hours agoWatch Dogs Is An Underrated Gem - Watch Dogs Game Review
3272 -
51:00
Sports Wars
5 hours agoBronny James Has DISASTROUS Debut, Caitlin Clark HATE Reaches New Level, Vikings Rookie DB Tragedy
22.4K37 -
41:05
Standpoint with Gabe Groisman
7 hours agoEp. 35. Saluting our Troops this Independence Day Weekend. Vice Adm. Herman Shelanski, USN (ret.)
32.5K16 -
45:54
The Why Files
14 hours agoHumans vs Superhumans | When Monsters Were Real and We Almost Went Extinct
45.9K48 -
23:03
TimcastIRL
7 hours agoBill O’Reilly Says Biden Will DROP OUT, Tucker Carlson Says Obama Wants Biden GONE
62.5K231 -
30:30
Stephen Gardner
1 day ago🔴BREAKING: Trump Trashes Biden while welcoming Kamala Harris
150K334 -
3:18:11
Fresh and Fit
19 hours agoBody Count Matters ONLY For Women. Change My Mind.
146K155 -
8:00
Adam Does Movies
1 day agoKILL Movie Review - Get Off The Train Already!
56.7K4