

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: Comparison Operators
incomplete
2: Comparison Operator Evaluations
incomplete
3: Comparison Practice
incomplete
4: If Statements
incomplete
5: If Practice
incomplete
6: If-Else
incomplete
7: If-Else Practice
incomplete
8: If-Else Practice
incomplete
9: Boolean Logic
incomplete
10: Boolean Quiz
incomplete
11: Should Serve Drinks
incomplete
12: Mount Rental
incomplete
13: Combat Advantage
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
It's often useful to only execute code if a certain condition is met:
if CONDITION:
# do some stuff here
# code after the if block may still run regardless
For example, in this code:
def show_status(boss_health):
if boss_health > 0:
print("Ganondorf is alive!")
return
print("Ganondorf is unalive!")
if boss_health is greater than 0, then this will be printed:
Ganondorf is alive!
Otherwise, this will be printed:
Ganondorf is unalive!
Without a return in the if block, Ganondorf is unalive would always be printed:
def show_status(boss_health):
if boss_health > 0:
print("Ganondorf is alive!")
print("Ganondorf is unalive!")
This code could print both messages:
Ganondorf is alive!
Ganondorf is unalive!
When you only want code within an if block to run, use return to exit the function early.
Indentation is what tells Python whether the body of a function or the if statement has ended. Don't forget the colon after your if statement :; it is a required part of the syntax!
Complete the print_status function.
player_health is less than or equal to 0, print the text dead to the console.status check complete to the console.