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 trialjohn herron
2,485 Pointspython code challenge
having trouble with this "else" statement
admitted = 20
if age > 13:
print ('true')
else:
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe first issue is the statement admitted = None
should not be changed. It is part of the base challenge code.
The second issue, the conditional is not correct. The conditional should be checking for 13 or more.
The last issue is the instead of printing 'true', the code should set admitted to True:
admitted = None
if age >= 13:
admitted = True
Once these are correct, the else
part is straight-forward:
admitted = None
if age >= 13:
admitted = True
else:
admitted = False
Cena Mayo
55,236 PointsKeep in mind that they want you to SET the value of the admitted variable, not print it. In addition, the first part of the challenge wants you to create an 'age' variable. As is, your code won't recognize the conditional in the if statement, since there's no age variable declared, and it looks like you're using the admitted variable instead. Admitted contains a boolean value, not an integer.
admitted = None
age = 13 #or whatever
if age >= 13:
admitted = True
else:
admitted = False
Hope that helps!
Chris Freeman
Treehouse Moderator 68,441 PointsFor this challenge, the code should not create an age
variable. The challenge will set a value for age
during the code evaluation. Actually setting the age
value will prevent the challenge from passing. You'll get the message:
"Bummer! Don't set the age
variable, I'll do that for you."
For posts related to specific challenges, I suggest running proposed answers through the challenges before posting. It has saved me from posting many mistakes.
Cena Mayo
55,236 PointsI did (and do) actually run through the exercises before posting, and this was passed as correct.
Chris Freeman
Treehouse Moderator 68,441 PointsSorry for assuming. Are you also running them through the on-line challenge checker? For me, this code does not seem to pass Task 2 and produces the "Bummer" message above.