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

Hervé Dauberton
8,163 PointsPart 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
4 Answers

Chris Freeman
Treehouse Moderator 68,460 PointsWhen 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
8,163 Pointsto 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
8,163 PointsWell, something else was badly written in my last version. It passed. Thank you again.

Chris Freeman
Treehouse Moderator 68,460 PointsYour 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

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

Chris Freeman
Treehouse Moderator 68,460 PointsCheck your indentation. A single decrement statement should be sufficient.

Hervé Dauberton
8,163 PointsYes, 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 !
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsI formatted your code properly and deleted your answers that you requested. You should be able to delete your own posts.