Lesson·difficulty 2/5·~15 min
Repair an inventory balance
Read the task → edit your code → Run to see the output → Run tests to check your answer.
Implement stock_balance(initial, changes).
The starter resets the balance on every change. Repair it to return the final balance after all signed integer changes. Empty changes must return initial. Explain a failing example before making your repair.
Before coding, predict one result by hand. After the tests pass, explain your approach and add a boundary example of your own.
Tests
- Case 1
- Case 2
- Case 3
- Case 4
✦ Need help with this task?
Sign in or create a free account to get AI help. Free includes a monthly AI allowance.
warming up
Loading editor…
Consolewaiting
$ Console output will appear here.