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

Jingru Zhang
Jingru Zhang
3,641 Points

can't pass this even odd challenge

I saved my code and ran it on my terminal, and it worked. But my code just wouldn't pass the challenge.

even.py
import random

start = 5

def even_odd(num):
    return not num % 2

while start: 
    number = random.randint(1, 99)
    if even_odd(number):
        print("{} is even.".format(number))
    else:
        print("{} is odd.".format(number))    
    start -=1

1 Answer

This is the most ridiculous reason for a challenge not passing, but your answer is the periods that you have in your print sentences. Remove those and you should be good to go.

import random

def even_odd(num):
    return not num % 2

start = 5

while start:
    random_number = random.randint(1, 99)
    if even_odd(random_number):
        print("{} is even".format(random_number))  # No period
    else:
        print("{} is odd".format(random_number))  # No period
    start -= 1
Jingru Zhang
Jingru Zhang
3,641 Points

Wow, thanks! I was punished for typing in complete sentences.. Please tell me why I can't put periods after the sentences...

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

HI Jingru Zhang

Basically, the only reason you cannot put periods is because of the specific answers the code checker is programmed to look for. Some (a very few) of the challenges would let it pass, but it really depends on the language and the type of return the checker is expecting..

So, it's not that your answer was incorrect, it just did satisfy the, often very picky, code checker. I look at it this way... more often than not, our own code needs to be very specific, so in a way, this help us to practice being very specific and helps us to develop a strong sense of the fine details. Honestly, I catch a lot more now than I did when I first started here. :smiley:

Keep Coding! :dizzy: