Welcome back to pre-AI programming, where buggy code was written by humans and your only tool was the debugger.
It was a simpler time, when it was just you and the code and the closest you got to “you’re absolutely right”
was unit tests passing.
In these exercises, you’re going to go old school and use the debugger and your knowledge of mathematical
notation to find and fix the bugs in the Python code. Construct test cases, trace through the output, and when
you think you’ve fixed all the bugs, submit your answer! There’s no time limit and no penalty for wrong answers,
so take your time and think through each problem.
Good luck!
Case 1The Missing Element
This function should add up every element of x, but sometimes it returns the wrong total. Find an input that exposes the bug, then repair the code.
Specification
s=j=0∑n−1xj
Symbol
Meaning
Shape
x
the input values
(n,)
s
their sum
scalar
Repair the compute function so that it matches the specification for every input.
Read the code
To leave the editor using only the keyboard, press Esc, then Tab.
Probe it
Repair it
Your progress is saved in this browser, on this device only. It is never uploaded, and it will be lost if you clear your browser's storage.