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 trialHassan Baukman
2,288 PointsWhy does it say it tell me wrong number of prints???
The runs 5 times and stops, so what is the problem?? Why does it say "wrong number of prints?
import random
start = 5
while start !=0:
start-=1
num=random.randint(1,99)
x=num%2
def even_odd(num):
if x !=1:
print(num, 'is even')
else:
print(num, 'is odd')
even_odd(num)
# Since 0 is falsey, we have to invert it with not.
#return not num % 2
1 Answer
Nicholas Ward
5,797 PointsJust two quick changes should fix it.
You are calling the
even_odd()
function outside of your while loop, so the while loop is running and not really doing anything, theneven_odd()
is being called only once. You need to switch the order of your while loop andeven_odd()
so that you can call the function in the loop, then move theeven_odd()
call into the loop.You want to calculate x inside of
even_odd
import random
start = 5
def even_odd(num):
x = num % 2
if x !=1:
print(num, 'is even')
else:
print(num, 'is odd')
while start !=0:
start-=1
num=random.randint(1,99)
even_odd(num)
Hope that helps!