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 trialDavid Gabriel
Python Web Development Techdegree Student 979 Pointsconditional 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")
# 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
16,266 PointsThe 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")
- You've named the function
number
, and there's no argument to it. - The if-else block is indented in a way that it is outside the function, so
if number % 2 == 0
is wrong, becausenumber
here refers to the name of your function, not the argument that was to it. - You're printing at the end, instead of
return
ing.
Here's the method body to get you started -
def even_odd(number):
# your code here
Good luck!