Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

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))
        print('{} is odd'.format(num))
    start -= 1

1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 145,623 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: