Challenge
Running totals
…and a top-up, then follow a battery through one orbit. A PRIMM challenge on updating variables.
Showing 1–10 of 34
Challenge
…and a top-up, then follow a battery through one orbit. A PRIMM challenge on updating variables.
Challenge
…variables: text, whole numbers, decimals and True/False. A PRIMM challenge on Python data types.
Challenge
A bare except: reports every fuel reading as bad, because it also catches a NameError from a typo. Predict the last line, find the hidden error, catch only ValueError and fix the typo, then write a…
Challenge
record_launch() adds 1 to a global counter and stops with an UnboundLocalError. Predict it, find out why Python treats the name as local, fix it by passing the count in and returning the new one, then…
Challenge
refuel() assigns to fuel_kg inside the function, creating a local variable and leaving the global fuel unchanged. Predict the last line, compare both values, fix it by returning the total, then write…
Challenge
add_sample(sample, log=[]) remembers samples from earlier calls, because the default list is created once and shared. Predict it, prove the calls share one list, fix it with None as the default, then…
Challenge
A call to schedule_launch() passes the pad where the rocket belongs, and the board says a launch pad is flying. Predict the line, find which parameter got which value, fix it with keyword arguments…
Challenge
add_reading() appends to the list it receives, so the caller's stored readings change too. Predict the first line, prove both names share one list, fix it by returning a new list, then write a filter…
Challenge
to_kelvin() prints its result instead of returning it, so the caller gets None. Predict the last line, find out what the function gives back, fix it with return, then write a conversion function that…
Challenge
status_light() returns None for Scrub because that branch sets a variable but never returns it. Predict the last line, find which statuses give None, make every path return, then write a function…