Return Values
STEP 3 is where functions stop being obedient little helpers and start becoming information-sending, value-returning WIZARDS.
Let’s make this thing SING.
Alright coder — up until now, your functions have been like:
“Okay boss, I’ll do the thing… but I won’t tell you anything.”
Cute. Helpful. But limited.
Now we give them the ability to send information back.
This is the moment your functions stop being one-way streets and start becoming two-way conversations.
1. What’s a Return Value?
A return value is what a function gives back after it finishes its job.
It’s like your function saying:
“Here you go — I did the thing, and here’s the result.”
Example:
def add(a, b):
return a + b
##Now you can use the result:
total = add(3, 5)
print(total)
Your function just did math AND delivered the answer like a polite pizza driver.
2. Why Return Values Matter for Games
Return values let you:
- calculate damage
- update health
- generate loot
- check if the player survived
- compute experience
- decide outcomes
- build entire game systems
This is where your game becomes smart.
3. Example: Damage Calculator
def calculate_damage(attack, defense):
return attack - defense
##Use it:
hit = calculate_damage(10, 3)
print("You dealt", hit, "damage!")
Your game now does math like a battle accountant.
4. Example: Healing Function
def heal(current_hp, amount):
return current_hp + amount
##Use it:
hp = heal(50, 20)
print("New HP:", hp)
Your hero now regenerates like a fantasy avocado.
5. Important Rule: return Ends the Function
Anything after return is ignored.def test():
return "Hello"
print("You will never see this")
Python: “Nope. I’m done.”
Practice (Your Turn!)
Mini-Challenge
Create a function called double(x) that returns twice the number.
Your function now multiplies like a caffeinated calculator.
You now understand:
- what return values are
- how functions send information back
- how to store and use returned results
- how to build smart, reactive game systems
- how to make your functions feel like magical vending machines
Your code officially thinks AND communicates.
Ready for Step 4, where we combine EVERYTHING — parameters, returns, logic — to build full game systems inside functions?


