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 trialRamon Berke
637 PointsI am stuck in this task can somebody tell my mistake?
The task says "Write a function named even_odd that takes a single argument, a number. return True if the number is even, or False if the number is odd. You can use % 2 to find out the remainder when dividing a number by 2. Even numbers won't have a remainder....". I did this but the bummer says "SyntaxError: def even_odd(5):". Can somebody tell my mistake?
def even_odd(5):
if even_odd % 2:
return True
else:
return False
1 Answer
Tizmiz Tizzer
1,040 PointsYour first problem is here.
def even_odd(5)
You are entering a number when you should be entering a parameter for that spot.
def even_odd(num)
This will solve your error.
Next you need to change your code a bit
def even_odd(num):
if num % 2 == 0:
return True
else:
return False
This will work because the if statement is checking if the number is divisible by 2, if it is the number, will not leave a remainder. Which is why we are checking if the remainder == 0. If the number has a remainder we know the number is not divisible by 2.
Ramon Berke
637 PointsRamon Berke
637 PointsThank you so much
Tizmiz Tizzer
1,040 PointsTizmiz Tizzer
1,040 PointsNo problem! Make sure you mark this as solved so other Python programmers can look for this answer if they get stuck on the same problem as well