CHAPTER 8

Magic Spells (Functions) ๐Ÿช„

Wizards don't chant the whole spell every time. They give it a short name like "Fireball!"

In coding, we group code into Functions so we can use it again and again.

โœจ Writing a Spell

We use the keyword def (define) to make a spell.

def say_hello():
    print("Hello Wizard!")

Casting the Spell:

Just write its name with parentheses!

say_hello()

YOUR QUESTS ๐Ÿงช

Quest 1: Write the Spell

Define a function called cheer that prints "Go Team!". Don't call it yet!

def cheer():
    print("Go Team!")
Waiting for you to run code...

Quest 2: Cast the Spell

Now call the function cheer() to see the message.

cheer()
Locked ๐Ÿ”’

Quest 3: Power Spell

Make a NEW function greet(name) that takes a name. Call it with your name.

def greet(name):
    print("Hello " + name)

greet("Cody")
Locked ๐Ÿ”’
๐Ÿง™โ€โ™‚๏ธ

Wizard's Review ๐Ÿ“œ

1. Which word starts a function definition?

โŒจ๏ธ SPELL BOOK
Waiting for spell...