""" looking at the babysitting problem in class """ def calc_money(start, end): """ Return amount of money charged. """ rate_switch_time = 9 # 9:00pm high_rate = 2.50 # $ per hour low_rate = 1.75 # $ per hour if end > rate_switch_time and start >= rate_switch_time: high_hours = end - start low_hours = 0 elif end > rate_switch_time and start < rate_switch_time: high_hours = end - rate_switch_time low_hours = rate_switch_time - start else: high_hours = 0 low_hours = end - start return high_rate * high_hours + low_rate * low_hours def time_to_hours(hr_min): """ Convert a time like '10:23' to fractional hours, with times after midnight continuing past 12, i.e. 2:34 is 14+(34/60.0) """ earliest_time = 4 # times earlier than 4:00 are am import string strings = string.split(hr_min, ':') # ['10', '23'] # print "strings = ", strings hour = int(strings[0]) + int(strings[1])/60.0 # print "hour = ", hour if (hour < earliest_time): hour = hour + 12 # print "hour = ", hour return hour def main(): print "babysit" start = time_to_hours(raw_input("start time = ? (hh:mm) ")) # print "start = ", start end = time_to_hours(raw_input("end time = ? (hh:mm) ")) # print "end = ", end print "the amount is $%0.2f " % calc_money(start, end) main()