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

Which fix removes the bug?

def count_evens(nums):
    c = 0
    for n in nums:
        if n % 2 == 1:
            c += 1
    return c
  1. Change c += 1 to c += n
  2. Change % 2 to % 3
  3. Start c at 1
  4. Change == 1 to == 0
Even numbers have remainder 0, so compare against 0.
Play Problem Solving ▸