Thresholds for a temperature label chain

A weather app labels an integer temperature t, in degrees Celsius, using this specification:


Label

Temperatures

hot

30 °C or higher

warm

20 °C up to but not including 30 °C

mild

10 °C up to but not including 20 °C

cold

above 0 °C but below 10 °C

freezing

0 °C or lower


A programmer writes the Python chain below, testing from the hottest label down, but leaves three thresholds as A, B and C.


Python
if t >= A:
    label = "hot"
elif t >= B:
    label = "warm"
elif t >= 10:
    label = "mild"
elif t > C:
    label = "cold"
else:
    label = "freezing"


For the chain to match the specification exactly, threshold A must be , threshold B must be and threshold C must be . Although the cold test never mentions an upper bound, that branch runs only when t is greater than 0 and less than . With these thresholds, a temperature of 0 °C receives the label .

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Chained Decisions Questions: