Patterns, Sequences, and Thinking Like a Mathematician
Discover hidden patterns in numbers, learn to write rules for sequences, and write your first Python program.
Materials for this lesson
- Laptop (charged)
- Pencil and paper
Warm-Up: What Comes Next?
Look at each sequence below. Can you figure out the pattern and predict the next three numbers?
2, 4, 6, 8, ___, ___, ___1, 4, 9, 16, 25, ___, ___, ___1, 1, 2, 3, 5, 8, ___, ___, ___
Core Lesson: The Language of Sequences
What is a Sequence?
A sequence is an ordered list of numbers that follows a rule. Mathematicians love sequences because they're everywhere — in nature, music, architecture, and computer science.
Every sequence has a rule (or formula) that tells you how to find any term. If you know the rule, you can find the 10th term, the 100th term, or even the millionth term — without writing them all out.
Arithmetic Sequences
An arithmetic sequence adds the same number each time. That number is called the common difference (d).
| Term | Value | How we got it | |--------|-------|-------------------| | 1st | 3 | start | | 2nd | 7 | 3 + 4 | | 3rd | 11 | 7 + 4 | | 4th | 15 | 11 + 4 | | nth | ? | 3 + 4 × (n - 1) |
The general formula for the nth term is:
a(n) = a(1) + d × (n - 1)
So for our sequence: a(n) = 3 + 4(n - 1) = 4n - 1
What is the 50th term of the sequence 3, 7, 11, 15, ...?
Geometric Sequences
A geometric sequence multiplies by the same number each time. That number is called the common ratio (r).
| Term | Value | How we got it | |--------|-------|-------------------| | 1st | 2 | start | | 2nd | 6 | 2 × 3 | | 3rd | 18 | 6 × 3 | | 4th | 54 | 18 × 3 | | nth | ? | 2 × 3^(n-1) |
Arithmetic = adding the same thing each time (grows linearly)
Geometric = multiplying by the same thing each time (grows exponentially — much faster!)
Which of these is a geometric sequence?
The Fibonacci Sequence
The Fibonacci sequence is special: each term is the sum of the two before it.
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
This sequence shows up everywhere in nature:
- The number of petals on flowers (often 3, 5, 8, 13, or 21)
- The spiral pattern of sunflower seeds
- The branching of trees
- The shape of seashells and galaxies
The Fibonacci Sequence in Nature — TED-Ed
Hands-On Lab: Your First Python Program
It's time to write code! We'll use Python to generate sequences automatically.
Getting Started
Open your browser and go to replit.com. Create a free account if you don't have one, then create a new Python project.
Program 1: Generate an Arithmetic Sequence
Type this into the editor and hit Run:
# Arithmetic sequence generator
start = 3
difference = 4
for i in range(1, 21):
term = start + difference * (i - 1)
print(f"Term {i}: {term}")
Try changing start and difference to create your own sequences. What happens if the difference is negative?
Program 2: The Fibonacci Sequence
Now let's generate Fibonacci numbers:
# Generate the first 50 Fibonacci numbers
a, b = 1, 1
for i in range(50):
print(f"Fibonacci #{i + 1}: {a}")
a, b = b, a + b
Notice how fast the numbers grow! By the 50th term, the number is over 12 billion.
Program 3: Make It Interactive
Let's let the user choose what kind of sequence to generate:
# Interactive sequence generator
print("=== Sequence Generator ===")
print("1. Arithmetic sequence")
print("2. Geometric sequence")
print("3. Fibonacci sequence")
choice = input("\nPick one (1, 2, or 3): ")
if choice == "1":
start = int(input("Starting number: "))
diff = int(input("Common difference: "))
n = int(input("How many terms? "))
for i in range(n):
print(start + diff * i)
elif choice == "2":
start = int(input("Starting number: "))
ratio = int(input("Common ratio: "))
n = int(input("How many terms? "))
value = start
for i in range(n):
print(value)
value = value * ratio
elif choice == "3":
n = int(input("How many Fibonacci numbers? "))
a, b = 1, 1
for i in range(n):
print(a)
a, b = b, a + b
else:
print("Invalid choice!")
Python basics you just learned:
for i in range(n)— repeat something n timesprint()— display outputinput()— ask the user for inputif/elif/else— make decisionsint()— convert text to a numberf"Term {i}: {term}"— format strings with variables
Challenge: Gauss's Trick
The story goes that when the mathematician Carl Friedrich Gauss was 10 years old, his teacher asked the class to add up all the numbers from 1 to 100. While his classmates started adding one by one, Gauss found the answer in seconds.
Your challenge: Can you figure out Gauss's trick? Find a formula for:
1 + 2 + 3 + 4 + ... + n = ?
Hint: What do you get if you add the first number and the last number? The second number and the second-to-last number?
Bonus: Write a Python program that checks Gauss's formula against a brute-force loop:
n = 100
# Method 1: Brute force (add them one by one)
total = 0
for i in range(1, n + 1):
total = total + i
print(f"Brute force: {total}")
# Method 2: Gauss's formula
formula = n * (n + 1) // 2
print(f"Gauss formula: {formula}")
# Do they match?
print(f"Same answer? {total == formula}")
Resources
- Python Basics — W3Schools — reference for Python syntax
- Replit — online code editor
- OEIS (Online Encyclopedia of Integer Sequences) — look up any sequence and find its rule
- Fibonacci in Nature — Math is Fun — more on Fibonacci