Question
By using Python 3.6: For this problem, you'll be defining a function that calculates the difference between two times of day, where the times of
By using Python 3.6: For this problem, you'll be defining a function that calculates the difference between two times of day, where the times of day are represented as strings in the form "h:mm", where h is a number of hours (any number of digits) and mm is the two-digit version of the minutes. So 4:08am would be represented by the string "4:08" and 9:59pm would be represented by "21:59". We want a function that when you input "4:08" and "21:59", will output "17:51".
And finally, you get to put everything together. Define a function time_between() that, given two strings in the form "h:mm" representing two times of day, computes the difference in time between them, returning its answer as a string. So for example, time_between("4:08","21:59") would return the string "17:51" and time_between("101:21","101:29") would return the string "0:08". You're allowed to assume that the second time will always be bigger than the first time.
How can I get to put them together?
This is my code:
def diff_min(mins1,mins2): """return two different times in minutes
number -> number""" return (mins1,mins2)
def time_to_str(time): """return tuple of numbers represents the time
tuple_of_numbers -> str""" return (str(time[0]) + ":" + str(time[1]))
def time_to_minutes(time): """returns hrs and mins to the total number of minutes
tuple_of_numbers -> int""" if time[0] > 0: return time[0]*60+time[1] else: return time[1]
def minutes_to_time(mins): """returns a tuple of two integers given an integer number of minutes
number -> tuple_of_numbers""" return (mins//60,mins%60)
def extract_time(time): """returns a tuple of two integers representing hrs and mins
str -> tuple_of_numbers""" return (int(time[:-3]),int(time[-2:]))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started