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

Wrong number of prints ? Not sure what I am doing wrong here.

Hello,

I am not sure what I am doing wrong here. I followed all that was asked but then it gets to the final part and says "Bummer wrong number of prints" when it asks me to print 2 times in the directions.

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

2 Answers

Cody Te Awa
Cody Te Awa
8,820 Points

Hi Joseph your code looks great everywhere except for a small hiccup on line 7 where the while statement is. Since you have:

start = 5
while start == False:
    #body of while loop
    start -=1 

The while loop never actually starts (which means 0 prints which explains the error) because start is not equal to false it is equal to 5 which is denoted in boolean as a true value. So alternatively you can get rid of the '== False' part all together and have it look like this:

start = 5
while start:
    #body of while loop
    start -=1 

This means that as long as the start variable is pointing to a non-zero value(anything thats not nothing) the while loop will run. And since you decrement the value of start after each iteration it will eventually reach 0 and will break out of the loop. Great job though Joseph! and Happy Coding :) -CodyTheCoder

Thanks so much for pointing that out !