Hassan Baukman1,151 Points
Why 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
Nicholas Ward5,797 Points
Just 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, then
even_odd()is being called only once. You need to switch the order of your while loop and
even_odd()so that you can call the function in the loop, then move the
even_odd()call into the loop.
You want to calculate x inside of
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!