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 trial

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

Anurag k
Anurag k
902 Points

even or add loop

can u please check and say y this code is not working ?

even.py
import random
start=5

while start !="":
    num=random.randint(1,99)
    even_odd(num)



def even_odd(num):
    start=start-1
    if num%2==0:
        print("{} is even".format(num))
    else:
        print("{} is odd".format(num))

1 Answer

Elad Ohana
Elad Ohana
24,456 Points

Hi Anurag

Couple of things are getting you into trouble: The even_odd function is already written, so you don't have to redefine it for this challenge. You should, however call it in your while loop (you should also write your code after the function definition, with the exception of your import statement). Another issue you're having is that your start variable will never equal "". Since "" is not equal to 0, you will have an infinite loop. Try to go about it this way:

import random keep function definition as is define your start variable start your while loop and figure out the correct condition for it to stop get your random number call your function to check if number is even or odd, then print the appropriate string decrement your start variable as described

Hope this helps