At My Fingertips
Rapid Playground
Have a look at these geometric figures:
A | B | C |
---|---|---|
We could call them stopwatches or timers or something like that. Here are some similarities:
Our goal is to develop a function named countdown_timer
that can produce any of the above figures:
def countdown_timer(...) -> Graphic:
Now let's focus on the differences between the above graphics,
so we can figure out what parameters our countdown_timer
function should have.
We see two differences:
Are those two differences independent, or is there a relationship between the number and the angle?
There is a direct relationship: the angle represents the number of minutes, like in an analog clock. Thus, we only need one parameter. For example, we can provide the number of minutes, and the function can compute the angle from that automatically.
def countdown_timer(minutes: int) -> Graphic:
Let's start by defining some constants that capture the style (colors and font) of our graphic, as well as its size.
Before starting to "hack", you may want to decompose the graphic into serveral components, like:
You could create a separate function for each component,
and test that function on its own.
After each of those functions work,
implement the countdown_timer
function
to compose these components into the overall graphic.
Play with your countdown_timer
function,
creating timers that show a different number of minutes.
What happens if you provide 60 as an argument? What about numbers greater than 60? What about less than 0?
You may want to add an assert
statement at the top of your minute_timer
function
to reject argument values outside the range your function supports.
Save your countdown_timer
function in your toolbox.
It might come in handy in the future,
for example if you ever need a set of timer icons,
for different times, to include in a presentation you create.
You are in control! You don't need to use the exact design given above. You can tweak your code so it produces countdown timers in a style you like!
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Countdown Timer
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 19a6bb6 (Mon, 27 Jan 2025 12:33:26 GMT)