I need help with writing a function to_secs
that converts hours, minutes, and seconds to a total number of seconds. In the book it says the following test should be possible:
to_secs(2, 30, 10) == 9010
I need help with writing a function to_secs
that converts hours, minutes, and seconds to a total number of seconds. In the book it says the following test should be possible:
to_secs(2, 30, 10) == 9010
There are 3600 seconds in an hour, 60 in a minute. The rest is simple arithmetic:
def to_secs(hours, minutes, seconds):
return hours * 3600 + minutes * 60 + seconds
Demo:
>>> def to_secs(hours, minutes, seconds):
... return hours * 3600 + minutes * 60 + seconds
...
>>> to_secs(2, 30, 10) == 9010
True