Problem 191580 · easy · Level 01 Prerequisites & Setup

Air Quality Label

elif chains · guard clauses · None · boundaries · py-conditionals

A street-side air monitor measures fine dust (PM2.5, in micrograms per cubic metre) and the city's website shows a label for each reading. Write air_label(pm25) that returns the label, using this simplified scale:

reading label
None (the monitor sent nothing) "no data"
below 0 (impossible, the monitor is faulty) "sensor fault"
at least 0 and below 12 "good"
at least 12 and below 35.5 "moderate"
at least 35.5 and below 55.5 "unhealthy for some"
at least 55.5 and below 150.5 "unhealthy"
150.5 or more "very unhealthy"

Readings may be integers or floats. A reading of exactly 0 is perfectly clean air.

Examples

Input:  pm25 = 8.2
Output: "good"

Input:  pm25 = 35.5
Output: "unhealthy for some"

Input:  pm25 = 0
Output: "good"

Input:  pm25 = None
Output: "no data"

Constraints

  • pm25 is None or a number between -1000 and 10**6

Goals

  • Write an elif chain that states each boundary exactly once
  • Handle missing and impossible values first with guard clauses, without mistaking 0 for missing
Starting Python…