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

fahad lashari
fahad lashari
7,693 Points

I don't really have an idea what they are asking me to do. I am novice so here is my crappy code...

Could some one please help me out with this task. And If you have the time, please can you explain what they are asking me to do.

kind regards,

even.py
import random 
start = 5
def even_odd(num):
    If % 2 is 0:
        return num is % 2
    else:    
        return not num % 2

while start not 0:
    number = random.randint(1, 99)
    if even_odd(number) == num is % 2:
        print('{} is even'.format(number))
    else:
        print('{} is odd'.format(number))
    start-=1    

It's a confusing one. Leave the even_odd() function as it is in the challenge. You don't need to do anything to it. The decrease increment will need to be in both the if and else. I got an INVALID SYNTAX on:

  • while start not 0:
  • That seems like it should work, but the challenge seems to be rejecting it
  • if even_odd(number) == num is % 2:
  • is getting an INVALID SYNTAX also. I get what your trying to do but it seems a bit convoluted
  • all in all you are pretty close. You can look at the code below or just try to work on those things.
while start: # is sufficient to say "run untill start is no longer True"

if even_odd(num): # is sufficient to say " if even_odd comes back as True"

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:
    number = random.randint(1, 99)
    if even_odd(number):
        print('{} is even'.format(number))
        start -= 1
    else:
        print('{} is odd'.format(number))
        start-=1    
fahad lashari
fahad lashari
7,693 Points

Hi john,

I already figured this one out and forgot to take off the question. Thanks for you answer!

Your help is much appreciated

Kind regards,

Well done then :D