Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

David Gabriel
seal-mask
.a{fill-rule:evenodd;}techdegree
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,266 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!