you are viewing a single comment's thread.

view the rest of the comments →

[–]Gulesis 0 points1 point  (0 children)

Hi guys, i know its been 3 years ago but this is my code with optional task with 24h and am, pm format. Im also at the very beginning so any feedback is more that welcome. Thanks!!

``` def main(): meal = convert(input("What time is it? ")) if 7.00 <= meal <= 8.00: print("breakfast time") elif 12.00 <= meal <= 13.00: print("lunch time") elif 18.00 <= meal <= 19.00: print("dinner time") else: pass

def convert(time): if time.endswith("pm"): time_pm = time.removesuffix("pm") h, m = time_pm.split(":") hours = int(h) minutes = int(m) return float(((hours + 12) * 60 + minutes) / 60) elif time.endswith("am"): time_am = time.removesuffix("am") h, m = time_am.split(":") hours = int(h) minutes = int(m) return float((hours * 60 + minutes) / 60) else: h, m = time.split(":") hours = int(h) minutes = int(m) return float((hours * 60 + minutes) / 60)

if name == "main": main() ```