🐸

The Final Spell

Python Basicspython-basics-32-the-final-spell
Reward: 200 XP
|

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 move is "run", print "Running!"
  • If move is "jump", print "Jumping!"
4
Action

Call escape with the list ["run", "jump", "run"].

Suggested Solution
Click to expand

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 Tips
Want more? Click to expand

This is the foundation of game development and automation scripts.

pymain.py
Loading...
Terminal
Terminal
Ready to run...