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

Young Gon Kwon
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!

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))
            print("{} is even".format(value))
        start = start - 1
    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
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
Young Gon Kwon
Courses Plus Student 1,426 Points

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