A response counted before the error
Predict the output · Medium · §13.2 A program that doesn't crash
This code adds up the survey responses that are numbers. Predict the output without running the code.
Code
answers = ["4", "five", "2"]
count = 0
total = 0
for a in answers:
try:
count += 1
total += int(a)
print("Added:", a)
except ValueError:
print("Not a number:", a)
print(count, total)Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.