pythonbeginner10 minutes

Fix the Bug in a Simple Even Number Checker

Identify and fix the bug in a Python function that is intended to check if a number is even.

Challenge prompt

The following Python function is supposed to return True if a number is even and False if it is odd. However, it doesn't work as expected. Find the bug in the code and fix it so that it functions correctly.

Guidance

  • Check the condition used to determine if a number is even.
  • Remember how the modulus (%) operator works with even and odd numbers.

Hints

  • The modulus operator returns the remainder after division.
  • An even number divided by 2 has a remainder of 0.

Starter code

def is_even(number):
    if number % 2 == 1:
        return True
    else:
        return False

Expected output

is_even(4) -> True is_even(7) -> False is_even(0) -> True

Core concepts

modulus operatorif conditionalsboolean return values

Challenge a Friend

Send this duel to someone else and see if they can solve it.