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

Doyle Lardell
PLUS
Doyle Lardell
Courses Plus Student 888 Points

looks like a glitch but my answer is still wrong

looks like a glitch but my answer is still wrong

not getting it keeps saying task 1 isnt working

even.py
import random
start = 5
def even_odd(num):
    num = random.randint(1,99)
    while start = True:

        if num % 2 = 0
            print("{} is even".format(bobby)
            start -= 1      
        else:
            print("{} is odd".format(bobby)
            start -= 1

    # If % 2 is 0, the number is even.
    # Since 0 is falsey, we have to invert it with not.
    return not num % 2

I think you need to change your operator to equals using == vs. a single = which is just an assignment

i.e.

if num % 2 == 0

Try that, maybe?

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

The structure of your code got confused. The while loop should not be inside of the is_even function, but rather, it should be built below the function and calls is_even as needed.

In addition to the structure, there were many syntax errors in the above code:

  • error line 5: need to use double-equals ==,
  • error line 7: need to use ==, missing colon end of line
  • error line 8: missing closing paren
  • error line 11: missing closing paren
  • use while start: instead of while start == True:
  • use num instead of the undefined bobby

Post back if you need more help. Good luck!!

Jonathan Beard
Jonathan Beard
1,681 Points

Solution:

Here is what I did

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