Answer to Question #232597 in Python for Assignment

Question #232597
Take an hour from the user as input and tell it is time for which meal.
• The user will input the number in a 24-hour format. So, 14 means 2 pm, 3 means 3
am, 18 means 6 pm, etc.
• Valid inputs are 0 to 23. Inputs less than 0 or more than 23 are invalid in 24-hour clock.
• Assume, Input will be whole numbers. For example, 3.5 will NOT be given as input.
==========================================================
Inputs: Message to be printed
4 to 6: Breakfast
12 to 13: Lunch
16 to 17: Snacks
19 to 20: Dinner
For all other valid inputs, say "Patience is a virtue"
For all other invalid inputs, say "Wrong time"
==========================================================
Sample Input:
4
Sample output:
Breakfast
Sample Input:
27
Sample output:
Wrong time
1
Expert's answer
2021-09-02T12:52:22-0400
hour= int(input())
if hour <0 or hour >23:
    print("Wrong time")
else:
    if hour >=4 and hour <=6:
        print("Breakfast")
    elif hour >=12 and hour <=13:
        print("Lunch")
    elif hour >=16 and hour <=17:
        print("Snacks")
    elif hour >=19 and hour <=20:
        print("Dinner")
    else:
        print("Patience is a virtue")





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS