Python Python Basics (2015) Letter Game App Even or Odd Loop

omri luz
omri luz
5,148 Points

Please tell me what is wrong with my code

i have no idea what i am doing wrong

even.py
import random
start = 5
while start == 5:
    def even_odd(num):
        num = random.randint(1, 99)
        if num % 2 == 0:
            print ("{} is even".format(num))
        else:
            print("{} is odd".format(num))
        start -= 1
    # If % 2 is 0, the number is even.
    # Since 0 is falsey, we have to invert it with not.
        return not num % 2

What error are you getting?

1 Answer

Robert Ionut Muraru
Robert Ionut Muraru
5,361 Points

Hello,

You are defining the even_odd() function within the while loop which is not necessary. You should use the even_odd() function inside the while loop to check if a number is even or not. Try writing the code again, you can leave the definition of the even_odd() function as it is and just create the while loop under it:

import random
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
start = 5

# here is how you could think about the remaining challenge:

'''while start is not falsey:
    declare a variable and assign to it the value you get using random.randint(1, 99)
    if that variable is even:
      print "{} is even",putting the random number in the hole
    else:
      print "{} is odd", again using the random number
    decrement start by 1 
'''

Hope it helps you.