In this video, learn how to use the time module to create a timer in Python. You can use the sleep method from the library to have your program count time for you.
- [Instructor] Let's create a timer with the Time module.…Of course, to use the time module we have to import it.…So we'll go import time.…And the way the timer is going to work is it's…going to go from zero to 10, and then once we hit 10…we're going to stop the timer and say we're done.…And so we'll want to ask the user,…when should we start the timer?…We're going to have this variable called run,…and we're going to use the input function…that we used in a previous video,…start, and then a little arrow here so…the user can then say yes we want to start.…
And so we'll have this other variable called seconds,…which is going to keep track of how many seconds have passed.…We'll start it at zero, and then we'll say if run,…meaning what the user responded, equals yes,…then we're going to go ahead and start the timer.…The way the timer's going to work is we're going to say,…while we haven't reached 10 seconds,…then we're going to go ahead and continue running the timer.…And so the first thing we'll want to do with this timer…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.