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

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

Could somebody please explain why this code doesn't pass the challenge?

So i've checked by code in a compiler, and also in workspaces and run the code, and it works fine, so there's no syntax errors.

The error I'm getting from the code challenge is 'wrong number of prints', yet it asks me to print either {} is odd or {} is even, which I have done.

If I'm making a mistake can someone please let me know? Otherwise this looks to be a bug?

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 start == True:
    rand = random.randint(1, 99)
    if even_odd(rand) == True:
        print("{} is even".format(rand))
    else:
        print("{} is odd".format(rand))
        start -= 1

1 Answer

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

Perfect, that was my mistake. All fixed! Thanks so much Henrik!