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

It looks like Task 1 is no longer passing.

can you help me with the code? once I get to step 3 it tells me task 1 not passing, is my code wrong?

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

2 Answers

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey there,

good job until here! You have two problems in your code now. Firstly you're using the format method on the print function but you have to use it on the string inside of the print function. That's the reason why task 1 no longer passes. The other problem is the condition of your loop because you should execute the loop until 5 becomes 0 (falsey).

If you fix those two issues it should look like this and work:

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

I hope that helps! :)

thank you so much