Digital Clock, In Class App¶
Contents¶
Indices and tables¶
Exercise Overview¶
For this week, the goal is to create an app that will display the current time in the terminal using a digital clock face.
The app should have the following functionality:
Clear the terminal
Fetch the current time from the system
Parse the hr:min:sec:am|pm fields out
Print the hr:min:sec:am|pm fields to the screen to resemble a digital clock
- A good reference for unicode blocks is here, though note that not all of them will make good pixel replica.
Sleep for 1 second and repeat…
This will require the datetime
class from datetime
package and the sleep()
method from the time
package.
You should setup a project in PyCharm in order to make debugging your app as simple as possible.
Stub Code¶
To allow you to focus on the main kernel of the program, some stub code has been created with the following functions in it:
gen_font_table()
- Generates a font table containing 8x8 characters. The font table is a dictionary, keyed by character / digit, with each character a 2-dimensional list of pixels. A pixel value of 0 represents off and a pixel value of 1 represents on. For example:tbl = {} tbl["0"] = ((0, 0, 0, 1, 1, 0, 0, 0), (0, 0, 1, 0, 0, 1, 0, 0), (0, 1, 0, 0, 0, 0, 1, 0), (0, 1, 0, 0, 0, 0, 1, 0), (0, 1, 0, 0, 0, 0, 1, 0), (0, 1, 0, 0, 0, 0, 1, 0), (0, 0, 1, 0, 0, 1, 0, 0), (0, 0, 0, 1, 1, 0, 0, 0),)
clear_screen()
- Handles sending the ASCII escape character to the terminal that clears the screen.Note
The terminal in PyCharm does not handle all ASCII terminal codes and so the
clear_screen()
method may not work in PyCharm for you. Instead, the text will just scroll vertically. If you run your app in a standalone Python interpreter, theclear_screen()
method should work correctly.
You can find the stub code here
.