Building Your Own Mental Shortcuts (That Actually Work)
What You'll Learn
How to package a set of steps into a named, reusable shortcut — so you can use it over and over without rewriting the same code.
Part 1
You Already Use Shortcuts
When someone says "make me a sandwich," they don't say "go to the kitchen, open the bread bag, take out two slices, put them on a plate, open the fridge, get the cheese…" They just say "make me a sandwich" and you know all the steps.
"Make a sandwich" is a shortcut — a single name that represents a whole series of steps. You use these all the time:
"Get ready for school" = wake up + brush teeth + get dressed + eat + pack bag
"Clean your room" = pick up clothes + make bed + organize desk + vacuum
"Send a text" = open phone + open app + type message + hit send
In programming, these shortcuts are called functions. A function is a named block of code that you can run whenever you want, just by using its name. You've already been using functions that Python provides — print(), input(), len(), int(). Today, you're going to learn to build your own.
Part 2
Your First Function
Let's start with the simplest possible function — one that just displays a greeting:
How Functions Work
def say_hello(): defines the function — it tells Python "here's a shortcut called say_hello, and here are the steps." The code inside (indented) is what the function does.
Defining a function doesn't run it. It just saves the recipe. Nothing happens until you call it.
say_hello() calls the function — it runs all the steps inside. The parentheses () are what tells Python "run this now."
We called it three times, and each time it printed the same three lines. Write once, use many times.
Part 3
Functions That Take Input
A function that does the exact same thing every time is useful, but limited. The real power comes when you can give it different information each time. This is like the difference between "make a sandwich" and "make me a grilled cheese sandwich" — you're giving it specific instructions.
What's a Parameter?
def greet(name): — the word name inside the parentheses is called a parameter. It's a placeholder — a blank slot that gets filled in when you call the function.
greet("Lena") — "Lena" is the argument — the actual value that fills the slot. Inside the function, name becomes "Lena".
Same function, different input, different output. The structure stays the same (that's abstraction!), but the details change.
You can have more than one parameter:
The order matters — the first argument goes into the first parameter, the second argument goes into the second parameter.
Part 4
Functions That Give Back an Answer
So far, our functions do things (they print). But sometimes you want a function to calculate something and give you back the answer, so you can use it elsewhere. That's what return does:
How return Works
return result sends the value back to wherever the function was called. The function stops running immediately after return.
answer = double(5) — Python runs the function with 5, gets back 10, and stores it in answer.
Think of it like a machine: you put something in (the argument), the machine does something to it, and gives you back a result (the return value).
Let's make a more useful function:
Look how useful that is! We wrote the bar-drawing code once, and now we can use it for health, energy, hunger, score — anything. That's the power of functions.
Part 5
Why This Changes Everything
Let's see the difference functions make. Here's code without functions:
That's a lot of repeated code. Now here's the same thing with a function:
Same output, but the code is shorter, cleaner, and easier to change. If you want to redesign the profile — add a border, change the bar style, add an emoji — you change it in one place and it updates everywhere.
Part 6
Building Response Styles
Let's start building our Text Conversation Simulator. The idea: different friends have different texting styles. One friend is super enthusiastic, another is sarcastic, another is supportive. We can capture each style as a function:
Each function takes the same input (your message) but processes it differently — just like your real friends would react differently to the same news. Run it several times to see the randomness.
Part 7
Functions Can Use Other Functions
Here's something powerful: functions can call other functions. This is like having a recipe that says "make the sauce (see sauce recipe on page 12)." You break big tasks into smaller named pieces:
Decomposition With Functions
show_player doesn't know how to make a bar or choose a title — it just asks the other functions to do those jobs.
This is decomposition (Lesson 1) taken to the next level. You break a complex task into named pieces, and each piece is a function.
If you want to change how bars look, you change make_bar. If you want different titles, you change get_title. The show_player function doesn't need to change at all.
Part 8
The Complete Text Conversation Simulator
Let's build the full project — a program that simulates a group chat where your friends each respond in their unique style:
How This Works
Each friend is stored as a list: ["Lena", enthusiastic]. The second item is the function itself — not a call to the function (no parentheses), but a reference to it.
friend_style(friend_name, your_message) calls whichever function is stored for that friend. Lena always gets enthusiastic(), Sam always gets sarcastic(), etc.
This is a powerful idea: functions can be stored in variables and lists, just like numbers and text. This lets us treat behavior as data.
Try sending a few messages. Type "quit" to exit. Notice how each friend's personality stays consistent — Lena is always hyped, Sam is always sarcastic. The functions define their character.
Part 9
What You Just Did
You learned to take a series of steps, give them a name, and reuse them whenever you want. That's what functions are — named, reusable shortcuts.
This is abstraction at its most powerful. When you use show_profile("Lena", "Soccer", 8), you don't need to think about how the profile gets displayed — the bars, the formatting, the borders. You just say "show the profile" and it happens. The complexity is hidden behind a simple name.
This is how every big program in the world works. A video game isn't one giant block of code — it's thousands of functions, each handling one small task: draw_player(), check_collision(), play_sound(), update_score(). Each one is simple on its own. Together, they create something complex.
The Big Idea
When you find yourself writing the same code more than once, make it a function. Give it a clear name, define what information it needs (parameters), and what it gives back (return). Now you have a reusable building block — and your code gets shorter, cleaner, and easier to change.
Thinking Questions
- What's the difference between defining a function and calling it? Why do we need both steps?
- When should a function
print()versusreturn? (Hint: think about whether you want to display the result or use it in more code.) - Can you think of daily tasks that work like functions? Something you do repeatedly that could be described with a name and inputs?
Challenges
Level Up
Challenge 1 · Greeting Card Generator
Create functions for different card types: birthday_card(name, age), thank_you_card(name, reason), get_well_card(name). Each should return a formatted card message. Build a menu that lets the user choose a card type, enter the details, and see the result.
Challenge 2 · Calculator Functions
Create functions for add(a, b), subtract(a, b), multiply(a, b), and divide(a, b). Each should return the result. Then build a calculator that asks the user for two numbers and an operation, calls the right function, and shows the answer.
Challenge 3 · Add a Personality
Add a new personality to the Group Chat Simulator. Create a function for a "mysterious" friend who responds with cryptic, philosophical one-liners. Or a "sports" friend who relates everything to athletics. Add them to the friends list and test the chat.
Summary
What You Learned
Thinking Skill
Encapsulation — packaging complexity into named, reusable units. When something is complex, hide the details behind a simple name. Ask: "Can I give this a name and reuse it?"
Python Concepts
def function_name(): — define a function
Parameters — inputs a function receives: def greet(name):
Arguments — actual values you pass in: greet("Lena")
return — send a value back from a function
Calling functions — use the name with parentheses: say_hello()
Functions calling functions — building complex behavior from simple pieces
Functions as values — storing functions in lists and variables
Lessons 1–8
Decomposition — break big problems into small steps
Abstraction — decide what details matter
Deductive Reasoning — rules + facts = conclusions
Categorization — organize items into groups
Pattern Recognition — spot what repeats and changes
Automation — templates for repetitive tasks
Inductive Reasoning — observations → conclusions
Encapsulation — package complexity into reusable functions