I need to make a program that when asked the number of minutes you sleep. ie 437. It will tell you 17:00 to 00:17, 18:01 to 01:18. Basically the times when the first and last digits are backwards and 437 minutes apart. I am having a hard time setting up the loops and if statements. How to I go about this? How many while or for loops will I need? Please help.
1
Expert's answer
2012-03-30T11:43:42-0400
# the function counts the number of minutes between two times # Input:
# t1, t2 - strings, represeting time in the form "HH:MM", # e.g. "15:32" # Output: # d - distance between these times in minutes. # It is assumed that t1 is before t2. # Even if t1="22:00" and t2="00:45", # then the distance is 45 + 2*60 = 165
def mins (t1, t2): # compte the minutes from 00:00 till t1 and t2 m1 = int(t1[0:2])*60 + int(t1[3:5]) m2 = int(t2[0:2])*60 + int(t2[3:5])
# if m2 > m1 then we should return m2-m1, # otherwise, we should return # m2 + (number of minutes in 24 hours=60*24-1440) - m1
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment