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

Adam Tyler
Adam Tyler
14,865 Points

'Wrong number of prints!'

My code produces an answer in work spaces correctly, i.e if num = 12 it will print '12 is even' or is num = 77 it will print '7 is odd', why is this the wrong number of prints?

even.py
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

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,857 Points

Hey Adam,

The challenge is not letting you pass, because it is expecting 5 different numbers to be checked. This is part of Task #2 when you assign start the value of 5.

Then, in Task #3, it wants the while loop to run as long as start is "truthy", but your loop will only run once, because you are checking to see if start equals 5, which it does but only for the first iteration of the loop. So, you are only checking one number instead of 5.

All your code is correct, except for the condition of the while loop. You just need to change that first line so it is checking if the value of start is "truthy" or "falsey" ... HINT: if you're checking for the "truthy" side of a boolean, you don't actually need a value there to check against. ... EXAMPLE: start == 5 checks if the value is five, but just start alone will check for truthy.

I hope this helps. Otherwise, good job. Just that one fix and it will pass.

Keep Coding! :dizzy: