1) What do I need to do?
π― Your mission: Power-up machine
Make def power_up(hero, amount): that prints a message using both.
Call it 3 times with different heroes and amounts.
2) What do I need to know?
Arguments: giving a function information
Put variable names inside the brackets when you def. These are called parameters.
When you call it, the values you pass in are called arguments.
def greet(name): β greet("Nova") puts "Nova" into name.
π§° Your toolkit for this mission
Everything you need to know to finish this lesson on your own:
Parameters
Names in the brackets of def that receive values.
How to write it: Separate with commas: def power_up(hero, amount):
def power_up(hero, amount):
print(hero, "gains", amount, "power!")Arguments
The actual values you pass in when calling.
How to write it: Same order as the parameters.
power_up("Blaze", 50)
power_up("Storm", 20)return
Sends an answer back from the function.
How to write it: return value. Then print or store the result where you call it.
def area(width, height):
return width * height
print(area(3, 4)) # 12print vs return
print shows something; return hands back a value you can use later.
How to write it: If the task says "returns", use return.
Think about it
Look at this code. What happens next, and why? Say it in your own words.
greet("Bolt")Watch & explore βΆ
Power-up: Arguments: giving a function information
See it happen
1 / 3def greet(name):
print("Hi", name)The parameter name is a slot waiting for information.
3) Run the code & terminal output
Press βΆ RUN and your program's messages appear here!


Captain Py
Our next adventure is yours to create.
