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

Young Gon Kwon
PLUS
Young Gon Kwon
Courses Plus Student 1,426 Points

Need support about "even_odd.py" : Wrong number of print

Hello, there~!

Keep showing that "Bummer! Wrong number of print". I can not find a clue why the message pups up. It was working at the workspaces.

Please let me know what is wrong with my code please~!

Thank you previously!

even.py
import random

start = 5
def even_odd(num):

    global start
    while start != False:
        value = random.randint(1,99)
        if value %2 != 0:
            print("{} is odd".format(value))
        else:
            print("{} is even".format(value))
        start = start - 1
        #print(start)
    return start


    # If % 2 is 0, the number is even.
    # Since 0 is falsey, we have to invert it with not.
    return not num % 2

2 Answers

Brett McGregor
PLUS
Brett McGregor
Courses Plus Student 1,903 Points

Hi there, I'm a Python beginner but I will try to assist you.

You will need to create the while loop outside of the even_odd function (i.e the while loop is not defined within any function in this challenge). That way you will not face the problem of accessing the start variable.

Also, Kenneth mentions to use the even_odd function to do the check for you. So you will need to replace that part of your code within the while loop to use the even_odd function.

I have code that works which I could post here... but have a try yourself and see if you can get it. ;)

[MOD: changed comment to answer - srh]

Young Gon Kwon
PLUS
Young Gon Kwon
Courses Plus Student 1,426 Points

Thank you for your support~! It was very critical clue to solve the quiz!