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

Logan Valdez
PLUS
Logan Valdez
Courses Plus Student 6,741 Points

How Do I Fix This?

Hello. In this challenge I am supposed to import random in Task 1, but when I try and submit my code it states that Task 1 is no longer passing. What can I do to fix this?

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

1 Answer

Hi Logan,

This is close! There are some changes to make to the while loop that will make your code fly.

  1. You can change the while declaration to "while start" -- since start is not zero, it is True, and when it reaches zero, it will evaluate as false. This will also take care of the first two lines of code in the while loop.
  2. Where you're trying to decrease the value of start, you are actually printing the expression "start - 1", which does not assign a new value to start. Once you change this expression, you'll be gold!

Please let me know if you have any questions and I'll be happy to help.