The Final Spell
It's time for the ultimate challenge! Hoppy is trapped in a maze and needs to use everything he's learned to escape.
You need to write a function that navigates through a path.
The Plan
path = ["forward", "forward", "turn", "forward"]
for step in path:
if step == "forward":
print("Walking...")
elif step == "turn":
print("Turning...")
Your Mission
1
The Function
Define a function called escape. It should take one parameter: steps (a list).
2
The Loop
Inside the function, loop through each move in steps.
3
The Logic
- If
moveis"run", print"Running!" - If
moveis"jump", print"Jumping!"
4
Action
Call escape with the list ["run", "jump", "run"].
Suggested SolutionClick to expandClick to collapse
You are combining functions, loops, and conditionals. You are a real programmer now!
def escape(steps):
for move in steps:
if move == "run":
print("Running!")
elif move == "jump":
print("Jumping!")
escape(["run", "jump", "run"])Advanced TipsWant more? Click to expandClick to collapse
This is the foundation of game development and automation scripts.
pymain.py
Loading...
Terminal
Terminal
Ready to run...