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

Arun Patel
Arun Patel
1,180 Points

Check Work is not happening and getting error "Reload".

Check Work is not happening and getting error "Reload". This has happened multiple times. It is not showing any error as well for the code.

even.py
import random

start = 5

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

while True:
    x = random.randint(1, 99)
    y = even_odd(x)
    if y == 'True':
        print("{} is even".format(x))
    else:
        print("{} is odd".format(x))
    start -= 1

3 Answers

Hello Arun Patel

It looks like your while loop is an infinite loop, so your code never finishes. So the challenge eventually ends it itself.

Im just giving you a hint because its better for your learning if you find the problem and understand what happened than me giving you the answer.

Let me know if that helps, or if you are still stuck on what to do. :)

Arun Patel
Arun Patel
1,180 Points

Hi Chris,

Thanks for the inputs. I was suspecting the same but still thought it would be shown as an error rather than the Code Check getting stuck and showing Reload Challenge. Will check again.

Yeah many of the challenges don't always provide the most useful error messages. But its kind of good because it makes you have to go step by step through your code and helps you learn to debug.

If its possible for you to do, 1 thing you can do is copy your code from the challenge and run it locally on your own machine if you have python installed. Sometimes youll have to provide your own sample data, because you wont always know what the challenge passes in on submission. But if you have an idea, you will get a better error with Python's stack trace on error. :)

Arun Patel
Arun Patel
1,180 Points

Thanks Chris. I was able to fix the code and the challenge completed. I even tried in locally on my PC.

import random

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

while start != False: x = random.randint(1, 99) y = even_odd(x) if y == True: print("{} is even".format(x)) else: print("{} is odd".format(x)) start -= 1

Yes! In other languages using a while True is considered a bad practice. But in Python you see it used quite often. But you just have to make sure the moment you write your while True its immediately an infinite loop. so the next statement you should write after that is your condition that will break you out of that loop or cause the loop to end.

Or just use a condition in place of the True at the start of the while if that makes sense.

Glad you got it to pass!