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 trialselcuk baran
3,526 PointsWhat is wrong with the code?
import random start=5 def even_odd(num): # If % 2 is 0, the number is even. # Since 0 is falsey, we have to invert it with not. return not num % 2
while start>=0:
a=random.randint(1,99)
if even_odd(a)=True:
print ('{} is even').format(a)
else:
print('{} is odd').format(a)
start=start-1
import random
start=5
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
return not num % 2
while start>=0:
a=random.randint(1,99)
if even_odd(a)=True:
print ('{} is even').format(a)
else:
print('{} is odd').format(a)
start=start-1
3 Answers
Alexander Davison
65,469 Pointsif even_odd(a) = True:
On the line above Python caused an error because Python thought you wanted to assign the variable even_odd(a)
to True
, since you used one equal sign. To fix this use two equal signs like this:
if even_odd(a) == True:
Good luck! ~alex
selcuk baran
3,526 PointsThanks. I tried it but not a solution yet
ronakeogh
30 PointsCan you post the challenge task please?
Alexander Davison
65,469 PointsTry doing the .format()
stuff inside the print function also :)
Change this:
print ('{} is even').format(a)
Into this:
print ('{} is even'.format(a))
And do this for the other prints also.
Good luck! ~alex
NOTE: You must do this and the other answer above :)