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

Python Python Basics (2015) Logic in Python If This Then That

About the "else"

if age>0: print("The big boy's club") else: print("You are all grown up.")

The big boy's club

What should I add in order to make the " else: print(" You are all grown up")" ??

1 Answer

Marilyn Magnusen
Marilyn Magnusen
14,084 Points

Hi Yungi,

To print "You are all grown up.", you need to have the conditional statement evaluate to false. The else clause only kicks in if what you have told the computer to check for evaluates to false.

Whenever you write an if/else statement, you're telling the computer what to do depending on two possible conditions. But you also need to tell give the computer enough information for it to work out what route to take. For example, if it's cold, tell me to wear a jumper, if it's hot, tell me to buy sun-block. The computer won't know which action to take unless you also give it the temperature.

So in your example, you've told the computer what to do based on different ages, but you also need to tell it what the age is like this (the below will print "The big boy's club")

age = 5

if age > 0:
    print("The big boy's club")
else:
     print("You are all grown up.")

to print You are all grown up, you should change the value of age to be less or equal to 0:

age = 0

if age > 0:
    print("The big boy's club")
else:
     print("You are all grown up.")

Once it knows what the age is, it can then work out what to print.

Hope this helps :)