Back

Code Challenge: Hat Size Checker

Difficulty  

divider

Objective

Ask the user for their head circumference in inches and report the matching hat size and message.

Skills to Practice

  • Prompting a user for input
  • Casting input to a decimal number
  • Writing boolean expressions with ranges
  • Branching with if / elif / else

Tasks

  • Create a new Python program named cc-hat-size-checker.
  • Prompt for a head size in inches. Decimals are allowed, so cast accordingly.
  • Use the reference table below to pick a size.
  • Display the hat size and its message.
CircumferenceHat SizeMessage
20–21SmallSnug fit for speedy thinkers
21–22.5MediumBalanced and brilliant
22.5–24LargeRoomy for big ideas
24 and upExtra LargeLegendary noggin detected

Notice the bands share their edges — 22.5 appears on two rows. An elif chain settles that for you, because only the first matching branch runs. Work out which size 22.5 ends up as, and decide whether that is the one you wanted.


Sample Output

Sample Output
Enter your head size in inches: 23 [Enter]
Hat size: Large
Roomy for big ideas.

Commence Challenge