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.
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 .
Unlock full course notes by signing up
Pricing a badge order
A school store sets the total price for a badge order using the Python code below. For the given order, what total is assigned? Answer in credits, to one decimal place.
True conditions and skipped tests
A courier calculates a delivery fee using the following Python code, where distance is a nonnegative distance in kilometres. Select every true statement about the chain.
Counting the effects of two chain errors
An arcade assigns bonus tokens from a whole-number score between 0 and 100 inclusive. The intended schedule is 2 tokens for scores 0–39, 5 tokens for scores 40–79, and 9 tokens for scores 80–100.
Two proposed Python versions appear below. For each version separately, count how many of the 101 possible scores receive an incorrect bonus. Give both counts as exact integers.
A chain versus separate ifs when a branch changes x
Two students write Java code that awards points and adjusts an integer x. Version 1 uses an else-if chain:
Version 2 is identical except that both else if keywords are replaced by separate if statements, so the final else belongs only to the if (x > 5) test:
Each version runs on its own, starting from x = 75 and points = 0. Give the final values of x and points after each version, as exact integers.