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 trialAhmed Naeem
353 PointsPython Basics IF challenge Task 1 and 2
Hi,
In the Python Basics IF challenge tasks 1 & 2 I can't understand what to do.
"I'm going to create a variable named age. I need you to make an if condition that sets admitted to True if age is 13 or more."
I did:- admitted = True age = 13 if age >= 13: print("True")
The above code went successful but I have tried many options to resolve the second task I can't get through. I tried ELSE and ELIF, don't know if both will used or only ELSE.
"Add an else to your if. In the else, set admitted to False."
Thank you in advance.
8 Answers
Gerald Wells
12,763 PointsIt is asking you if age is greater than 13 admitted = True:
if age > 13: #if age is greater than 13
admitted = True #than admitted = True
Shawn Matthew
1,908 PointsI don't think any of you helped. He was asking about the second part.
Gerald Wells
12,763 PointsDid you read his code and the challenge?
Jeremy Kerrigan
12,002 Pointsadmitted = None if age >= 13: admitted =[1]
Tomasz Necek
Courses Plus Student 7,028 Pointsadmitted = None age = 14 if age >= 13: admitted = True
Michael Guthrie
1,924 PointsI had similar issue. I fixed it by reformatting my text to be in line with the first task.
if age > 13:
admitted = True
else:
admitted = False
Isaac Rosa
Courses Plus Student 1,744 Pointsit's actually |
if age >= 13: admitted = True
I hit a speed bump on this one also but reading this helped me find the answer thanks
Joseph Bowers
313 Pointsadmitted = None if age>=13:admitted=True else:admitted=False
Gerald Wells
12,763 PointsFun Fact
This won't pass the coding challenge due to the constraints placed on the validators, however this reduces the need for garbage collection and the number of instructions the processor has to interrpret.
admitted = (False, True)[age >= 13]
Commenting Tip
Just so you know.... To make it easier on those who read your code
Single Grave Accent -- on either side encompassing the text -- Backtick key is located next to the '1' below the Esc key
Tripple Grave Accents
``` <--- Triple Grave Accents
[Code here]
```
To make it colorful:
```python3 <--(whatever language you are using)
[Code here]
```
print("I am using python syntax highlighting here")
Brody Reineks
655 Pointsadmitted = None if age >= 13: admitted = True