Lesson 10 · Systems Thinking

The Assembly Line in Your Head: Chaining Ideas Together

What You'll Learn

How to connect functions together like links in a chain — where the output of one becomes the input of the next — to solve complex problems step by step.

Everything Is a Pipeline

Think about how a sandwich shop works. One person takes your order. Another slices the bread. Another adds the fillings. Another wraps it up. Each person does one job, then passes the result to the next person.

No single person makes the whole sandwich. Instead, the sandwich flows through a pipeline — a series of steps where each step transforms it a little and passes it along.

You think like this all the time. When someone asks "Is this a good day for a bike ride?" your brain runs a pipeline:

Check weather → Check energy level → Check if bike has air → Check schedule → Combine into a decision

Each step produces a result, and that result feeds into the next step. In code, this means the output of one function becomes the input of another. Today, we're going to master this technique — and use it to build a Friendship Score Calculator.

Connecting Functions Together

We already know how to make functions that return values. The key insight is: you can use a function's return value anywhere you'd use a normal value.

Python

The Chain

Raw text → clean() → cleaned text → score_length() → score

Each function does one small job. The output of clean() becomes the input of score_length().

You can even write it in one line: score = score_length(clean(raw_input)). Python reads from the inside out — it runs clean() first, then passes the result to score_length().

Python · One-Line Chaining

Breaking a Complex Problem Into Steps

Let's think about the Friendship Score Calculator. How do you rate a friendship? It's complex — there's no single number. But we can decompose it into measurable parts:

Friendship Score Components

Responsiveness — how quickly do they text back?

Generosity — do they share snacks, help with homework?

Fun Factor — how much fun do you have together?

Reliability — can you count on them?

Each component gets its own function. Then we chain them together into a final score. Let's build each one:

Python · Individual Score Functions

Each function handles one piece of the puzzle. They're simple on their own — the power comes from combining them.

The Combining Function

Now we need a function that takes all the individual scores and combines them into one final rating. This is the end of the pipeline:

Python · Combining Scores

See the pipeline? Individual scores → calculate_total() → percentage → get_title() → label. Each function does one transformation.

Visualizing the Flow

Let's add a display function and trace how data flows through the entire system:

Python · Tracing the Pipeline

The Pipeline

Raw answers → 4 scoring functions → 4 individual scores → combine function → percentage → title function → label

Each step is simple. But chained together, they create something sophisticated — a system that takes messy human input and produces a clear, meaningful output.

This is systems thinking — understanding how independent parts work together in sequence, where each part transforms information before passing it on.

The Master Function

We can wrap the entire pipeline in one "master" function that orchestrates everything:

Python · Master Function

New Things

sum(scores) adds up all the numbers in a list. So sum([8, 10, 8, 7]) gives 33.

min(value, 10) caps a value at 10 — if someone rates fun as 6, 6 * 2 = 12, but min(12, 10) keeps it at 10.

scores, pct, title = rate_friendship(...) — a function can return multiple values! Python unpacks them into separate variables.

The master function rate_friendship() doesn't do any scoring itself — it just calls the right functions in the right order. It's the conductor of the orchestra.

Comparing Friends

Now that the pipeline is wrapped in one function, we can easily run it for multiple friends and compare:

Python · Comparing Friends

New Things

friends.items() loops through a dictionary giving you both the key (name) and value (data) each time.

rate_friendship(*data) — the * "unpacks" a tuple so each item becomes a separate argument. ("instant", "yes", "yes", 5, "always") becomes five separate values.

results.sort(key=lambda x: x[1], reverse=True) sorts the results by the score (position 1) from highest to lowest. Don't worry about the lambda syntax yet — just know it tells Python which value to sort by.

The Complete Friendship Score Calculator

Python · Complete Calculator

Pipelines Are Everywhere

What you built is exactly how real software works:

Real-World Pipelines

Instagram filters: take photo → adjust brightness → add color tint → apply blur → add frame → output

Spell check: take text → split into words → check each word → mark misspelled → suggest corrections → display

Grade calculator: take assignment scores → weight each one → calculate average → convert to letter grade → display

Video game damage: base attack → multiply by weapon → subtract armor → check for critical hit → apply to health → display

In every case, data flows through a series of transformations. Each step is a function. Each function does one thing well. Together, they create something complex and useful.

What You Just Did

You learned to chain functions together — where the output of one becomes the input of the next. This is systems thinking: understanding how simple parts connect to create complex behavior.

The friendship calculator isn't one big, complicated function. It's a pipeline of small, simple functions that each do one job. Any single function is easy to understand, test, and change. But connected together, they solve a complex problem.

The Big Idea

Complex problems become manageable when you think of them as pipelines: "What are the steps, and how does information flow from one step to the next?" Each step is a function. Each function transforms the data and passes it along. Simple parts, complex results.

Thinking Questions

  1. Why is it better to have many small functions than one giant function? (Hint: think about changing, testing, and reusing.)
  2. If you wanted to add a "Humor" category to the friendship score, what would you need to change? How many functions would you need to touch?
  3. Can you think of a process in your life that works like a pipeline? What are the steps, and what flows through them?

Level Up

Challenge 1 · Movie Rating Pipeline

Build a movie rating system with functions for: score_acting(), score_story(), score_visuals(), score_music(). Combine them into an overall rating with a title like "Masterpiece", "Worth Watching", "Skip It". Rate 3 movies and display a ranked list.

Challenge 2 · Text Transformer Pipeline

Build a text processing pipeline: clean(text)censor(text, banned_words)emphasize(text, keyword)format_output(text). Each function transforms the text and passes it to the next. Test it with a sentence that has bad words and important keywords.

Challenge 3 · Day Planner Pipeline

Build functions: check_weather() returns a weather score, check_energy() returns an energy score, check_schedule() returns a free-time score. Chain them into plan_day() that recommends activities based on the combined scores. Different combinations should give different recommendations.

What You Learned

Thinking Skill

Systems Thinking — understanding how independent parts work together in sequence, each transforming data before passing it on. Ask: "What are the steps, and how does information flow between them?"

Python Concepts

Function chaining — output of one function becomes input of next

Nested callsf(g(x)) runs g first, then passes result to f

Master/orchestrator functions — functions that call other functions in order

Returning multiple valuesreturn a, b, c

sum() — add up all items in a list

min() — cap a value at a maximum

*data — unpack a tuple into separate arguments

.items() — loop through dictionary keys and values

.sort() with key — sort by a specific value

Lessons 1–10: The Complete Toolkit

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 functions

Generalization — build solutions that adapt to any input

Systems Thinking — connect simple parts into complex pipelines