Python Python Basics (2015) Number Game App Even or Odd

David Gabriel
David Gabriel
Python Web Development Techdegree Student 979 Points

conditional statement

Hi all,

Can you please have a look at my conditional statement below:

executed if condition evaluate to True

execute if condition evaluate to False

def number(): number = 13 if number % 2 == 0: print(number, "is even") else: print(number, "is odd")

even.py
# executed if condition evaluate to True
# execute if condition evaluate to False 
def number():
    number = 13
if number % 2 == 0:
    print(number, "is even")
else:
    print(number, "is odd")

1 Answer

Manish Giri
Manish Giri
16,264 Points

The instruction asks you to create a function called even_odd, whose argument will be number -

Write a function named even_odd that takes a single argument, a number.

From the function, you return True if the argument is even, or false otherwise.

In your code -

def number():
    number = 13
if number % 2 == 0:
    print(number, "is even")
else:
    print(number, "is odd")
  1. You've named the function number, and there's no argument to it.
  2. The if-else block is indented in a way that it is outside the function, so if number % 2 == 0 is wrong, because number here refers to the name of your function, not the argument that was to it.
  3. You're printing at the end, instead of returning.

Here's the method body to get you started -

def even_odd(number):
    # your code here

Good luck!