Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using python, write code for problem. 37. Military Time In military time, hours

ID: 3842483 • Letter: U

Question

Using python, write code for problem.

37. Military Time In military time, hours are numbered from 00 to 23. Under this sys tem, midnight is 00, 1 a.m. is 01, 1 p. m. is 13, and so on. Time in hours and minutes is given as a four-digit string with minutes following hours and given by two digits rang- ing from 00 to 59. For instance, military time 0022 corresponds to 12:22 a.m. regular time, and military time 1200 corresponds to noon regular time. Write a program that converts from military time to regular time. See Fig. 3.16

Explanation / Answer

def timeconvert(): print "Hello and welcome to Python Payroll 1.0." print "" # User input for start time. Variable stored. start = raw_input("Enter your check-in time in military format (0900): ") # User input for end time. Variable stored. end = raw_input("Enter your check-out time in military format (1700): ") print "" # --------------------------------------------------------------------------- # Present user input in standard time format hhmm = hh:mm # --------------------------------------------------------------------------- import datetime, time convert_start = datetime.time(hour=int(start[0:2]), minute=int(start[2:4])) # need to find a way to subtract 12 from the hour to present end time in standard time convert_end = datetime.time(hour=int(end[0:2]), minute=int(end[2:4])) print 'You started at', convert_start.strftime("%H:%M"),'am', 'and ended at', convert_end.strftime("%H:%M"), 'pm' # --------------------------------------------------------------------------- # Use timedelta to caculate time worked. # --------------------------------------------------------------------------- # print datetime.timedelta timeconvert() raw_input("Press ENTER to exit program") # Closes program.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote