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

"Oops! It looks like Task 1 is no longer passing." What??? - Even or Odd Loop

Here's my code for the Even or Odd loop:

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) == 0:
        print("{} is even").format(num)
    else:
        print("{} is odd").format(num)
start -= 1

Whenever I check the code I keep on getting this error message:

Oops! It looks like Task 1 is no longer passing.

I don't get it because Task 1 just asks you to import the random library. This is really frustrating....

1 Answer

The message about Task 1 no longer passing is indeed misleading, it is most likely caused by the fact that the way your code is written right now the program will crash, but the cause of that is not the code you added in stage 1.

There are two decently big issues with your code.

          print("{} is even").format(num)

format is a method that belongs to strings, it needs to be used directly on the string, the way this code is written you are trying to call format on the print method rather than the string itself.

This is the correct way to format the string:

          print("{} is even".format(num))

That is the first issue that would cause your program to crash, the same issue of course also applies to the other print statement but I won't cover that separately.

The second issue is the fact that you loop never ends, the statement that decreases the start variable has the same indentation as the while statement which means that it is not within the loop.

Awesome, thanks! I fixed all the silly issues you mentioned.

l also removed '==0:' in my loop and now it passes.