Problem 184251 · easy · Level 01 Prerequisites & Setup

Greeting by the Clock

conditionals · ranges

Write greeting_for_hour(hour) that takes an hour on a 24-hour clock and returns:

  • "Good morning" for hours 5 to 11
  • "Good afternoon" for hours 12 to 16
  • "Good evening" for hours 17 to 20
  • "Good night" for hours 21 to 23 and 0 to 4
  • "Invalid hour" if hour is not between 0 and 23

Examples

Input:  hour = 9
Output: "Good morning"

Input:  hour = 17
Output: "Good evening"

Input:  hour = 24
Output: "Invalid hour"

Constraints

  • hour is an integer, possibly negative or larger than 23

Goals

  • Map ranges of a number onto labels
  • Validate input before classifying it
  • Handle a range that wraps past midnight
Starting Python…