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.
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.Indentation matters! Indentation is what tells Python whether the body of a function or the if statement has ended. Also, don't forget the colon after your if statement :; it is a required part of the syntax!