Lesson 2 · Abstraction

Your Brain's Filing System: Why Forgetting the Details Makes You Smarter

What You'll Learn

How to identify what information matters and what can be ignored — and how to use Python to store, organize, and display only the essential details about anything.

The Problem With Knowing Everything

Quick: describe your best friend.

Did you list every single thing about them? Their exact height in centimeters? The color of their shoelaces? How many times they blinked today?

Of course not. You probably said something like: "She's funny, she likes soccer, and she always shares her snacks." You picked out the important stuff and ignored the rest.

Perhaps you're unaware of it, but that's kind of a superpower. It's called abstraction.

What Is Abstraction?

Abstraction means deciding what matters and ignoring what doesn't. It's the opposite of trying to remember everything. It's about creating a simplified version of something complex so you can actually work with it.

You do this all the time without noticing. A contact in your phone is an abstraction of a real person — it only stores name, number, and maybe a photo. It doesn't store their shoe size, their breakfast preference, or their mood. Why? Because that information isn't useful for the purpose of a phone contact.

Today, we're going to use abstraction (plus the Python skills we learned in Lesson 1) to build a Friend Stats Tracker: a program that stores the important details about your friends and displays personalized profiles.

Quick Review

Before we start building, let's make sure you remember the key tools from Lesson 1. Run this to warm up:

Python · Review

Change the name and mission to what we'll do today (the mission is to build a Friend Stats Tracker). Then run the code again.

Good. You remember variables and print(). Now let's learn something new.

Python Knows Two Kinds of Information

In Lesson 1, everything we stored in variables was text — things inside quotation marks, like "Shadow" or "Hello, World!". Python calls these strings.

But there's another kind of information Python understands: numbers.

Python

Key Difference

"11" with quotation marks is text — just the characters 1 and 1. You can't do math with it.

11 without quotation marks is a number — Python understands it as a quantity. You can add, subtract, multiply with it.

This matters more than you'd think. Try changing friend_age to "11" (with quotes) and see if it still works. It does — but watch what happens in the next section.

Doing Math With Numbers

The whole reason numbers exist in Python (separately from text) is so you can calculate things. Let's try some basic math:

Python

Math Symbols in Python

+ means add (you already know this one — it also joins text!)

- means subtract

* means multiply (not ×, because × isn't on your keyboard)

/ means divide

Try changing the age and see how the calculations update automatically. That's the power of using variables — change one thing, and everything connected to it updates.

A Tricky Problem With input()

In Lesson 1, we used input() to ask the user for their spy name. Let's try using it to ask for someone's age:

Python · This Will Break!

O-oh, that gave an error! What happened here?

Before we figure that out, you have to understand something: errors in coding happen all the time — and that's okay! They're just signals that something isn't working as expected. Learning to read and understand errors is a key skill in programming. It usually takes some time to find and fix this "bug" (yes, errors are called "bugs" in programming), so arm yourself with patience and curiosity. Read the output that shows error carefully — it tells you exactly what went wrong.

Note: 'concatenate' means to join things together. In Python, when you use + with text (strings), it joins them together — like "Hello" + "World" becomes "HelloWorld".

Why It Broke

Here's the thing: input() always gives you text, even if the user types a number. So when you type 11, Python sees it as "11" (text), not 11 (a number).

You can't add 1 (a number) to "11" (text). That's like trying to add 1 to the word "cat" — it doesn't make sense to Python.

So how do we fix this? We need to convert the text into a number. Python has a command for that: int().

You may have noticed that some pieces of code look like int(). In the last lesson you learned print(). Whenever you use a command with parentheses like int(), you're using something called a function. Functions are like mini-programs that do one specific job. In Python they have parentheses, and you can pass information into them (called "arguments"). Functions are like recipes for making things (like cakes); all you have to do is put some ingredients inside their parentheses, and voila: you get a finished cake!

Python · Fixed!

What Just Happened

input() gives us "11" (text). We store it in age_text.

int(age_text) converts "11" (text) into 11 (a number). We store that in age.

Now age + 1 works because both are numbers. You can also write this in one line: age = int(input("How old are you? ")) — that does both steps at once.

Try it — enter your age and see the math work. Then try the one-line shortcut by editing the code.

Choosing What Matters

Now you're ready to tackle abstraction. We're going to build a Friend Profile — but first, we need to decide: what information do we actually need?

Think about a real person. There are thousands of facts about them: hair color, shoe size, number of pets, favorite song, what they ate for lunch, how fast they can they swim 200 yards butterfly style, what time they woke up today…

We can't store all of that. We shouldn't store all of that. We need to abstract — pick out the essential details for our purpose.

For a Friend Stats Tracker, what matters? Let's think about what would be useful and fun:

The Abstraction Decision

We'll keep: Name, age, favorite game, a fun inside joke, and a friendship level (1-10)

We'll ignore: Height, weight, school schedule, parents' names, address, what they wore yesterday, what's their Roblox username…

This is abstraction in action. We looked at something complex (a whole human being!) and created a simplified model with only the parts that matter for our purpose.

Note: a model is a simplified representation of something complex. It's like a map of a city — it doesn't show every building, but it shows the most important roads and landmarks.

Let's start building — one piece at a time:

Python · Collecting Friend Data

Notice how we used int() for age and friendship level (numbers we might do math with) but left name, favorite game, and inside joke as regular text. That's another abstraction decision — which pieces of information need to be numbers and which can stay as text.

Also, notice that we can put functions inside functions — like int(input()). This is called nesting. It's a powerful way to combine operations. Here's a silly question for you: would we get a number or a string if we did this str(int("4"))? How about int(str(int("4")))?

Building a Profile Display

Now let's make the output look good. We'll display all the information in a clean, organized profile — like a character stats screen in a video game.

Python · The Profile Card

New Thing · str()

We just hit the reverse of the int() problem. When you join text with +, everything needs to be text. But age is a number.

str(age) converts a number into text: 11 becomes "11". It's the opposite of int().

So: int() converts text → number. str() converts number → text. You use whichever direction you need.

Run it and enter info about a real friend. See how the profile looks? You just built a simplified model of a real person — that's abstraction.

Making It Visual

The friendship level is just a number right now — 8/10. Let's make it visual with a bar made of characters. Remember the * symbol for multiplication? It works on text too:

Python · String Multiplication

What Just Happened

"ha" * 3 gives us "hahaha" — it repeats the text 3 times.

"█" * level repeats the filled block character level times.

"░" * (10 - level) fills the rest with empty blocks. If level is 7, that's 3 empty blocks. Together, you always get 10 blocks total.

Try changing level to different numbers between 1 and 10. Watch the bar change.

The Complete Friend Stats Tracker

Let's put everything together — data collection, math, visual display:

Python · The Complete Tracker

Try making profiles for two or three different friends. Notice how the same program creates completely different outputs depending on the input — but the structure stays the same. That structure is your abstraction.

What You Just Did

Let's think about what happened here. You took something incredibly complex — a real human being with millions of details — and you created a useful model using just five pieces of information: name, age, favorite game, inside joke, friendship level.

That's abstraction.

The most important lesson is this: the details you chose depended on your purpose. A doctor would abstract a person differently (blood type, allergies, medical history). A teacher would choose different details (grades, learning style, attendance). A video game would use health points, attack power, and speed.

There's no single "right" abstraction. The right abstraction depends on what you're trying to do.

The Big Idea

When you face a problem with too much information, ask yourself: "What actually matters here? What can I safely ignore?" The ability to simplify without losing what's important — that's one of the most powerful thinking skills you can develop.

Thinking Questions

Talk these over with someone, or think about them for a bit:

  1. If you were building a tracker for a sports team instead of friends, what five pieces of information would you keep?
  2. Why did we ignore things like height, hair color, and address? Can you think of a program where those would matter?
  3. What's an example of abstraction you use in everyday life? (Hint: maps, contact lists, report cards, and emojis are all abstractions.)

Level Up

If you want to push further, try these. Each one requires you to make abstraction decisions — what details to keep and what to ignore.

Challenge 1 · Pet Profile

Create a Pet Stats Tracker. Decide which 4-5 details matter for a pet profile (species? name? age? cuteness level?). Include at least one calculation and one visual bar.

Challenge 2 · Compare Two Friends

Modify the tracker to collect info about two friends, then display both profiles side by side. Add a line that shows who is older and whose friendship level is higher.

Challenge 3 · Game Character Creator

Build a character creator for an imaginary game. The player gets 20 points to distribute between Strength, Speed, Intelligence, and Charm. Use bars to display each stat. Hint: you'll need to make sure the total doesn't exceed 20!

What You Learned

Thinking Skill

Abstraction — identifying what information is essential and ignoring what isn't. Always ask: "What actually matters for my purpose?"

Python Concepts

Numbers vs. text11 (number, no quotes) vs. "11" (text, with quotes)

Math operators+ add, - subtract, * multiply, / divide

int() — convert text to a number: int("11") gives 11

str() — convert a number to text: str(11) gives "11"

String multiplication"ha" * 3 gives "hahaha"

if/elif/else review — choosing different outputs based on values

Lesson 1 + Lesson 2

Decomposition — break big problems into small steps

Abstraction — decide what details matter and ignore the rest