Home › Course contents › Level 11: Perfect Timing
if … else …
Level 11: Perfect Timing
Chapter 1 · Starter Village
shielded() tells you whether the Reefclaw is hiding in its shell right now. Use if to decide:
if shielded(): # if it's in its shell
defend() # defend
else: # otherwise
attack() # attack
defend() blocks this turn's attack. Note that if and else both end with a colon, and the code under them is indented.
GoalDefeat the Reefclaw (60 HP) within 12 turns. Hitting the shell costs you 25 HP.
TipFollow the example above. Remember: an if inside a for needs 4 more spaces.
Starting code
# Repeat 12 turns: for i in range(12):
# Each turn, check with if shielded(): — defend() if it's in its shell, otherwise attack()