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 trialEmilio Andere
495 PointsWhy is my exercise wrong
I thought it was correct
import random
even.odd = random.randint(1,10)
while True:
if even_odd == ('2', '4', '6', '8', '10'):
return(True)
break
else:
return(False)
1 Answer
Tomas Svojanovsky
26,680 PointsHI, you need to write a function. Your code is not general, it works only for 5 numbers. To check if it is odd or even you can use modulo.
def even_odd(num):
return num % 2 == 0
Diwakar Singh
785 PointsDiwakar Singh
785 Pointsyou need write a function named even_odd if a number is passed into the function you can use the basic logic if you divide the number by 2 and you get reamainder as 0 then number will be even and function will return true and if remainder is 1 then it will be odd and function will return false you can use this code for reference def even_odd(number): if(number%2==0): return True else: return False