You should be able to do the easy part with your current knowledge while advanced will need you to do some research on your own (It’s related to next week’s subject). Answers to both of these questions will be available at solutions 24 hours before the next lecture.
Easy
Make a function that will take two variables hour
and minute
. And return the time in words.
Example:
1
2
3
4
5
6
>>> def time2words(hour, minute):
....
....
....
>>> print(time2words(15, 30))
three thirty pm
Think about how you can write the same function with less lines. Don’t forget that there are more object types than just strings / integers and more operators than ==
.
Advanced
Make a function that will take a single time_string
and return the time in words.
Example:
1
2
3
4
5
6
>>> def time2words(time_string):
....
....
....
>>> print(time2words('15:30'))
three thirty pm