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
Richard McKee
2,670 Pointsif else statements
Im having a problem in workspaces where I can't do if/else statements without getting errors.
some are generic errors but some I don't know what I'm doing wrong.
if anyone can help me find the error of my ways that would be most helpful
age=5000
if age > 10000:
... print('apple')
.... else:
print("pear')
1 Answer
Ryan S
27,276 PointsHi Richard,
The first thing is that your indentation looks like its off. The if/else statements should be aligned and the print functions should be indented in this case.
The second is that your quotations don't match around "pear"
If you are trying to do this in the python shell, it should look like this:
>>> age = 5000
>>> if age > 10000:
... print('apple')
... else:
... print('pear')
Hope this helps.
Vijay Ramdass
13,275 PointsVijay Ramdass
13,275 PointsJust to expand on this, it looks like the pear in your else statement has mixed quotations. The beginning of pear is double quotes ("), while after is single (').
print("pear')Richard McKee
2,670 PointsRichard McKee
2,670 PointsThanks actually it just made sense in my head! I didn't think indentation would factor in python because you write in separate lines!