How does counting operations turn a stopwatch reading into a formula, and how can a running program count its own operations?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Here is a function that converts Fahrenheit to Celsius:
def f_to_c(f): shifted = f - 32 return shifted * 5 / 9
Count the primitive operations one call to f_to_c performs, treating each arithmetic operation and each assignment as one unit. Assign the count under this lecture's rules, where the return counts as an operation too, to ops_now, and the count under last lecture's rules, where it does not, to ops_before.