$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #64

Which fix removes the subtle bug?

try:
    value = int(raw)
except:
    value = 0
  1. Catch narrowly: except ValueError:
  2. Catch narrowly: except Exception as:
  3. Move the assignment above the try
  4. Add an else: branch after the except
A bare except also swallows KeyboardInterrupt and real errors; catch the specific one.
Play Problem Solving ▸