$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #127

What is the correct fix?

nums = [1, 2, 3]
print(nums.index(9))
  1. Check first: if 9 in nums: before index
  2. Check first: if nums.has(9): before index
  3. Change index(9) to nums.find(9) here
  4. Wrap the print call in a str() cast
list.index raises ValueError when the value is absent — unlike JS indexOf, it never returns -1.
Play Problem Solving ▸