Answer to Question #116116 in Python for Mohit

Question #116116
ask user to input the time of the day (just the hour as an integer between 0 and 23) and decide whether it’s morning (between 0 and 12 inclusive), afternoon (between 13 and 17 inclusive), evening (between 18 and 19 inclusive), or night (between 20 and 23 inclusive).
1
Expert's answer
2020-05-16T13:46:37-0400
def main():
    # Firstly, we need to convert the result of input() for further processing
    hours = int(input("Enter the time of the day (0-23): "))

    # Now we need a if-elif staircase to select and print the answer
    if 0 <= hours <= 12:
        print("It's morning")
    elif 13 <= hours <= 17:
        print("It's afternoon")
    elif 18 <= hours <= 19:
        print("It's evening")
    elif 20 <= hours <= 23:
        print("It's night")
    else:
        print("It isn't an integer value between 0 and 23")

if __name__ == "__main__":  # is the file is running as a script, not importing
    main()  # call the main() function

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
New on Blog
APPROVED BY CLIENTS