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

Challenge 3 o 3 - make a while loop that runs until start is falset

Inside the loop - I am getting "task 1" not working and its just 'Import random" I moved the while start loop under the function and am just stuck. 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.
    while start:
        num = ranmdom.randit(1,99)

        if even_odd(num):    
            print('{} is even').format(num)
        else:
            print('{} is odd').format(num)
    start -=1

    return not num %2
Julio Garcia
Julio Garcia
1,944 Points

If I remember correctly that part of the course, the while loop need to be outside the function, just move the return not num % 2 before the while loop, and indent correctly the while. Also the .format(num) needs to be inside the print parentesis, like this.. print('{} is even'.format(num))

1 Answer

rydavim
rydavim
18,814 Points

Looks like Julio Garcia might have you sorted, but just in case - it looks like you just have two small issues. Your code needs to be outside the even_odd(num) function, and your print statements need to include the format method.

import random
start = 5
def even_odd(num):

    # Your while loop here should be outside the even_odd(num) function. 
    # This means it would be inline with import, start, and even_odd.
    while start:
        num = ranmdom.randit(1,99)
        if even_odd(num):    
            print('{} is even').format(num) # You'll need to make sure format is inside the print, attached to the string.
        else:
            print('{} is odd').format(num) # Something like: print('{} is odd'.format(num))
    start -=1

    return not num %2 # Don't forget that this return is inside the even_odd(num) function! Don't move it when you move the while loop!

That should do it, happy coding!