Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Hervé Dauberton
Hervé Dauberton
8,163 Points

Part 3 of the odd/even Python challenge

Hi,

I wonder if something wrong with my code or if it's a problem with the website. Nobody seems to have meet specifically that. It happens with me on the challenge odd/even in the last part of the Python course. I do the first two parts but when i check the last part, it doesn't pass. The odd thing is that the message says the part 1 is not valid anymore and it was just adding a random. I didn't erase so i don't understand at all what happens.

My code :

#part 1
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
#part 2
start=5
#part 3
while start:
  num=random.radint(1,99)
  if even_odd(num):
    print("{} is even".format(num))
  else:
    print("{} is odd".format(num))
  start-=1

I formatted your code properly and deleted your answers that you requested. You should be able to delete your own posts.

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,154 Points

When you get to the message "task one is no longer passing" it usually means that a syntax error has been introduced. The line

num=random.radint(1,99)

has a typo. It should be randint.

A new syntax error causes all tasks to fail checking hence the message.

Hervé Dauberton
Hervé Dauberton
8,163 Points

to Chris: Thank you for your answer. Unfortunatly even with randint() well written, i've got the same error. There must be another mistake somewhere. If i manage to properly write code on a question before finding a solution, i will ask again with my new version.

to Jason: Thank you and sorry for all that.

Hervé Dauberton
Hervé Dauberton
8,163 Points

Well, something else was badly written in my last version. It passed. Thank you again.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,154 Points

Your code with the typo fixed passes the Even or Odd Loop challenge:

#part 1
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
#part 2
start=5
#part 3
while start:
  num=random.randint(1,99)  # fixed typo
  if even_odd(num):
    print("{} is even".format(num))
  else:
    print("{} is odd".format(num))
  start-=1

Interesting, I couldn't pass the challenge with similar code as yours. I passed my by adding 'start-=1' under 'if' and 'else'

Chris Freeman
Chris Freeman
Treehouse Moderator 68,154 Points

Check your indentation. A single decrement statement should be sufficient.

Hervé Dauberton
Hervé Dauberton
8,163 Points

Yes, i said it on the commentary a little while after my answer. I had added others typos when i rewrited the code. I wasn't focused enough. Thank you !