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

Marvin Krachhel
Marvin Krachhel
4,341 Points

Import Random

I do not know why the error message for my code says that Task 1 is not working anymore.. In Task 1 I just had to import random, since Task 1 I did not change the import at all, but now that I wrote some Code for Task 3, the message says Task 1 is the problem. There might be mistakes left in the rest of my code, but this error message does not help to fix them at all and i do not really understand it too. Little side note : I also do not really get why I have to invert 0, because it is false. The second # note says that :)

Hope for quick response and I am happy about any kind of help on that task ...

even.py
import random

start = 5

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

2 Answers

Afloarei Andrei
Afloarei Andrei
5,163 Points
  1. Move the "even_odd" function above the while loop. So you will have the function then the loop.
  2. Change the "if answer == 0:" to "if answer == 1:"
Marvin Krachhel
Marvin Krachhel
4,341 Points

Thank you for your quick response :)