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

Even_odd challenge works on my local machine but not in here :(

Below is the Code I am using to print the even and odd numbers

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

Output from my local machine: Lionels-Air:workspace Lionel$ python evv_odd_challenge.py 28 is even 41 is odd 72 is even 91 is odd 58 is even

Output here:

Oops ! It looks like Task1 is no longer passing

Is my code not doing what it is supposed to do ?

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

I tried to make all kinds of helpful notes but after I thought I had it I rechecked my solution and it failed. So I started over and erased everything. Got a passing answer, checked it again SAME answer, it failed, checked it again SAME answer it passed. So, my solution below works, but I'm gonna check yours again. There's only one thing on yours I KNOW you missed. Parenthesis on the print functions. I'm gonna check yours a few times WITH the print functions corrected

All you need is parenthesis for the print function. Mine is below, it's slightly more succinct, but yours is fine.

2 Answers

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: # Make a while loop that runs until start is falsey.
    random_number=random.randint(1,99) # Inside the loop, use random.randint(1, 99) to get a random number between 1 and 99.
    if even_odd(random_number): #  If that random number is even (use even_odd to find out),
        print("{}  is even".format(random_number)) # <-- left off print parenthesis
    else:
        print( "{} is odd".format(random_number)) # <-- left off print parenthesis
    start -= 1

Yes indeed it was the parenthesis !! Thank you for taking the time to look at it. I also like your version of the solution better :)