

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 9
click for more info
Not enough gems
Cost: 6 gems
1: Functions
incomplete
2: Function Review
incomplete
3: Multiple Parameters
incomplete
4: Printing vs. Returning
incomplete
5: Where to Declare Functions
incomplete
6: Order of Functions
incomplete
7: Community
incomplete
8: Boots Interview
incomplete
9: Solutions
incomplete
10: None Return
incomplete
11: Multiple Return Values
incomplete
12: Parameters vs. Arguments
incomplete
13: Default Values
incomplete
14: Curse
incomplete
15: The Training Grounds
incomplete
16: Enchant and Attack
incomplete
17: Archmage
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
A function can return more than one value by separating them with commas.
def cast_iceblast(wizard_level, start_mana):
damage = wizard_level * 2
new_mana = start_mana - 10
return damage, new_mana # return two values
When calling a function that returns multiple values, you can assign them to multiple variables.
damage, mana = cast_iceblast(5, 100)
print(f"Damage: {damage}, Remaining Mana: {mana}")
# Damage: 10, Remaining Mana: 90
When cast_iceblast is called, it returns two values. The first value is assigned to damage, and the second value is assigned to mana. Just like function inputs, it's the order of the values that matters, not the variable names. We could just as easily have named the variables one and two:
one, two = cast_iceblast(5, 100)
print(f"Damage: {one}, Remaining Mana: {two}")
# Damage: 10, Remaining Mana: 90
Descriptive variable names make your code easier to understand, so name them well!
The damage and new_mana variables from cast_iceblast's function body only exist inside of the function. They can't be used outside of the function. More on that later when we talk about scope.
Complete the become_warrior function. It accepts 2 inputs:
full_name stringpower integerIt should return 2 values:
title stringnew_power integer.full_name the warrior
Be very careful with the output of your program. The text will need to match the expected results exactly. Double-check your spacing and spelling!
Here's an example of how the function is intended to work:
title, power = become_warrior("Aang Airbender", 100)
print(title)
# "Aang Airbender the warrior"
print(power)
# 101