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.
# Version A if score >= 40: bonus = 5 elif score >= 80: bonus = 9 else: bonus = 2
# Version B if score > 80: bonus = 9 elif score >= 40: bonus = 5 else: bonus = 2
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.
Thresholds for a temperature label chain
A weather app labels an integer temperature t, in degrees Celsius, using this specification:
A programmer writes the Python chain below, testing from the hottest label down, but leaves three thresholds as A, B and C.
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 ________.
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.