From CS50P Problem Set 1, Meal Time:
“Structure your program per the below, wherein convert is a function (that can be called by main) that converts time, a str in 24-hour format, to the corresponding number of hours as a float. For instance, given a time like “7:30″ (i.e., 7 hours and 30 minutes), convert should return 7.5 (i.e., 7.5 hours)”
This is my code:
time = input("What time is it? ")
hr, mn = time.split(":")
hr = int(hr)
mn = int(mn)
def main(hr, mn):
if hr == (7) and mn in range(00, 59):
print("Breakfast Time")
elif hr == (8) and mn == (00):
print("Breakfast Time")
elif hr == (12) and mn in range(00, 59):
print("Lunch Time")
elif hr == (13) and mn == (00):
print("Lunch Time")
elif hr == (18) and mn in range(00, 59):
print("Dinner Time")
elif hr == (19) and mn == (00):
print("Dinner Time")
else:
print()
convert(hr, mn)
def convert(hr, mn):
hr = int(hr)
mn = int(mn)/60
time = hr + mn
print(float(time))
if __name__ == "__main__":
main(hr, mn)
This is what check50 tells me:
Convert successfully returns decimal hours
Did not find “7.5” in “Input: “
Aaron Elder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.