logo CodeStepByStep logo

enough_time_for_lunch

Language/Type: Python if/else parameters return

Write a function named enough_time_for_lunch that accepts four integers hour1, minute1, hour2, and minute2 as parameters. Each pair of parameters represents a time on the 24-hour clock (for example, 1:36 PM would be represented as 13 and 36). The function should return True if the gap between the two times is long enough to eat lunch: that is, if the second time is at least 45 minutes after the first time. Otherwise the function should return False.

You may assume that all parameter values are valid: the hours are both between 0 and 23, and the minute parameters are between 0 and 59. You may also assume that both times represent times in the same day, e.g. the first time won't represent a time today while the second time represents a time tomorrow. Note that the second time might be earlier than the first time; in such a case, your function should return False.

Here are some example calls to your function and their expected return results:

callvalue returned
enough_time_for_lunch (11, 00, 11, 59)True
enough_time_for_lunch (12, 30, 13, 00)False
enough_time_for_lunch (12, 30, 13, 15)True
enough_time_for_lunch (14, 20, 17, 02)True
enough_time_for_lunch (12, 30, 9, 30)False
enough_time_for_lunch (12, 00, 11, 55)False
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.