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 trialDominick McCleary
3,012 Pointshow would i declare the number in this script
It wants a number for the function even_odd but every time i put a number in it, it says syntaxerror
def even_odd(5):
if even_odd() % 2:
return True
else:
return False
2 Answers
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsYou have the number 5 inside the (), you need to put a parameter like x, or you could use a keyword argument like x=5, this would mean if you called the function with no inputs it would set x=5 as the default.
you still need to do something with the x in the function however.
In you function you are calling the function again, if it were not for the syntax error I think you would also hit a recursion error. If you did define the parameters for the function as I described above it would keep calling itself to no end.
you are also not checking if the number is even or odd.
the if keyword needs the statement after it to evaluate to true or false, which yours will since you get a truthy value back, but to check if even you need to do:
<number> % 2 == 0
Ashton Norton
7,704 PointsFirst you need to replace the argument in the parentheses with a variable name, like number. Then you need to perform modulo against it. If the modulo evaluates to 0, then it's even.
Dominick McCleary
3,012 Pointsi got past the syntax error but now it is not returning the correct answer
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsJames J. McCombie
Python Web Development Techdegree Graduate 21,199 Pointsdef even_odd(x): "check if x is even": return True else: return False
Dominick McCleary
3,012 PointsDominick McCleary
3,012 Pointsthank you
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsJames J. McCombie
Python Web Development Techdegree Graduate 21,199 Pointsyour very welcome