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

stuck in this task

I think I've done everything correctly, generate the random integer; check if it is even to print; and decrement the start variable; can somebody help me?

even.py
import random

start = 5

while start = 5:
    num = random.randint(1, 99)

    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

    if even_odd(num) = True:
        print "{} is even".format(num)
    else:
        print "{} is odd".format(num)

    start - 1

1 Answer

Stuart Wright
Stuart Wright
41,119 Points

There are a few issues with your code:

  • In Python, you use == for testing equality, rather than simply =. So you need to change this in your while and if statements.
  • The print function requires parentheses. You need to add these to both of your print statements.
  • To decrement start, the correct syntax is either start = start - 1, or start -= 1 for short.
  • After fixing these syntax errors, there is still one problem. The challenge asks you to run the loop until start is 'falsey' (i.e. 0). You are currently only running it while start = 5.

Try to solve it with these hints and if you need any more help let me know.