So we should prompt the user to input time as #:## a.m./p.m., the function convert should convert the inputted time to a float, return the float value and use print adequate text.
I'm receiving an Error stating that the convert function isn't returning a decimal value, but the terminal is passing all the tests, when I type in manually.
What's the issue?
def main():
text = input("time here: ")
time = convert(text) # call the function convert() and assign it to time variable, different from the one in the function
print(time, type(time)) # check if the function returns a float value
if 7 <= time <= 8: # simple logic for defining time
print("breakfast time")
elif 12 <= time <= 13:
print("lunch time")
elif 18 <= time <= 19:
print("dinner time")
elif time >= 24: # ensure that you can't type in number > 24
print("Not a valid time point.")
else:
None # print None (null) for other cases
def convert(time):
hour, minute, period = time.replace(":", " ").split(" ") # unpack the list with 3 arguments (3rd arugment is period = am/pm) and define floats
hour = float(hour)
minute = float(minute) / 60
n_time = hour + minute # assign to a new variable n_time which should return float
return round(n_time, 2) # return float, rounded to 2 decimals
if __name__ == "__main__":
main()
As per the spec:
This line will error with that input:
hour, minute, period = time.replace(":", " ").split(" ") # unpack the list with 3 arguments (3rd arugment is period = am/pm) and define floatserrors
The Challenge says [emphasis added]:
The Challenge must handle either format.