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

still Task 1 redo error. please help - Even Odd loop for challenge 3 of 3

I still get the Task 1 redo error. am at a loss - please help

even.py
import random

start = 5

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

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

indentation of 'while' block needs addressing, but i am not sure if that would solve the problem.

Am all set - thanks everyone for your help!

Joelle Kruczek , what was the problem?

1 Answer

rydavim
rydavim
18,814 Points

Krishna Pratap Chouhan and anyone else who ends up finding this via search -- it looks like the following two things were the problem.

import random
start = 5
def even_odd(num):
    return not num % 2

    # This whole while loop needs to be outside the even_odd() function block.
    # It should be inline with import, start, and def even_odd().
    while start:
        rnum = random.randint(1,99)
        if even_odd(rnum):
            print(""{}" is even".format(rnum)) # Here, the {} placeholder brackets need to be part of the string, not outside it.
        else:
            print(""{}" is odd".format(rnum)) # The same goes for here - it should be "{} is odd".format().
        start -=1

I suspect those were the items he figured out after your comment. Happy coding, everyone!