Question: Write a program that asks the user to enter a number of seconds, and works as follows:
There are 60 seconds in a minute. If the number of seconds
Although divmod() has been mentioned, I didn't see what I considered to be a nice example. Here's mine:
q=972021.0000 # For example
days = divmod(q, 86400)
# days[0] = whole days and
# days[1] = seconds remaining after those days
hours = divmod(days[1], 3600)
minutes = divmod(hours[1], 60)
print "%i days, %i hours, %i minutes, %i seconds" % (days[0], hours[0], minutes[0], minutes[1])
Which outputs:
11 days, 6 hours, 0 minutes, 21 seconds