Lesson 3.1: Code is Instructions for the Computer
Duration: 45 minutes
Learning Objectives
After completing this lesson, you will be able to:
- Explain what programming is in simple terms
- Understand how computers interpret and execute instructions
- Recognize the difference between human language and programming languages
- Write your first pseudo-code instructions
Introduction
You've been programming your whole life without knowing it. Every time you followed a recipe, gave someone directions, or explained how to play a game, you were essentially programming a human. The only difference with computers is that they need instructions to be extremely precise.
Programming is simply writing instructions that a computer can understand and execute.
Main Content
What is Code?
Code is a set of written instructions. Just like a recipe tells you how to bake a cake step by step, code tells a computer what to do step by step.
Here's a simple comparison:
| Recipe for Humans | Code for Computers |
|---|---|
| "Add 2 cups of flour" | flour = 2 |
| "Mix until smooth" | mix(ingredients) |
| "Bake at 350°F for 30 minutes" | bake(350, 30) |
The key difference? Computers are literal. They do exactly what you tell them, nothing more, nothing less.
The Precision Problem
Imagine telling a robot to make a peanut butter sandwich. You might say:
"Put peanut butter on bread."
A human would understand this perfectly. But a computer might:
- Try to place the entire jar on the bread
- Not know which side of the bread to use
- Not realize it needs to open the jar first
- Not know how much peanut butter to use
To a computer, you'd need to say:
1. Pick up the bread bag
2. Open the bread bag
3. Remove two slices of bread
4. Place both slices on the plate
5. Pick up the peanut butter jar
6. Twist the lid counterclockwise to open
7. Pick up the knife
8. Insert knife into jar
9. Scoop approximately 1 tablespoon of peanut butter
10. Spread peanut butter evenly on one slice
11. Place the other slice on top
12. Done
This level of detail is what programming requires.
How Computers Execute Code
Computers don't understand English, Russian, or any human language. They only understand machine code — sequences of 1s and 0s called binary.
Human writes: print("Hello")
↓
Translator converts to machine code:
01001000 01100101 01101100 01101100 01101111
↓
Computer executes and displays: Hello
The "translator" that converts your code to machine code is called a compiler or interpreter (we'll learn more about these later).
The Building Blocks of Code
All programming, regardless of the language, uses these fundamental concepts:
┌─────────────────────────────────────────────────────────────┐
│ PROGRAMMING BASICS │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ Store information │
│ │ VARIABLES │ Example: age = 25 │
│ └─────────────┘ │
│ │
│ ┌─────────────┐ Make decisions │
│ │ CONDITIONS │ Example: if age >= 18 then "adult" │
│ └─────────────┘ │
│ │
│ ┌─────────────┐ Repeat actions │
│ │ LOOPS │ Example: repeat 10 times: print "Hi" │
│ └─────────────┘ │
│ │
│ ┌─────────────┐ Reusable instruction sets │
│ │ FUNCTIONS │ Example: calculateTax(price) │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Pseudo-code: Planning Before Coding
Before writing actual code, programmers often write pseudo-code — instructions written in plain language that describe what the program should do.
Example: ATM Withdrawal
START
Ask user for PIN
IF PIN is correct THEN
Ask for withdrawal amount
IF amount <= account balance THEN
Dispense cash
Update account balance
Print receipt
ELSE
Show "Insufficient funds"
END IF
ELSE
Show "Invalid PIN"
END IF
END
This isn't real code, but it clearly describes the logic. Once you have this, translating it to any programming language becomes much easier.
From Idea to Execution
Here's the journey from your idea to a running program:
┌──────────┐ ┌──────────────┐ ┌─────────────┐ ┌──────────┐
│ YOUR │ → │ WRITE CODE │ → │ TRANSLATE │ → │ COMPUTER │
│ IDEA │ │ (Source) │ │ (Compile) │ │ EXECUTES │
└──────────┘ └──────────────┘ └─────────────┘ └──────────┘
Example:
"Show greeting" → print("Hello!") → 01001000... → Hello!
Why Learn to Code?
Programming gives you superpowers:
| Without Code | With Code |
|---|---|
| Calculate 1000 numbers manually | Process millions in seconds |
| Send emails one by one | Send thousands automatically |
| Check one website for updates | Monitor hundreds simultaneously |
| Repeat boring tasks daily | Automate them once, done forever |
Programming isn't about being a "computer person." It's about solving problems efficiently and automating repetitive work.
Practice Exercise
Task 1: Write Pseudo-code
Write pseudo-code for a simple traffic light system. The light should:
- Show green for 30 seconds
- Then yellow for 5 seconds
- Then red for 30 seconds
- Repeat forever
Example Solution
START
REPEAT FOREVER
Turn light GREEN
Wait 30 seconds
Turn light YELLOW
Wait 5 seconds
Turn light RED
Wait 30 seconds
END REPEAT
END
Task 2: Spot the Missing Instruction
This pseudo-code for making coffee has a problem. What's missing?
START
Fill kettle with water
Boil water
Put coffee in cup
Pour water into cup
Add sugar if desired
Drink coffee
END
Answer
Missing instructions:
- Turn on the kettle (it won't boil by itself!)
- Wait for water to boil
- Stir the coffee after pouring water
- Wait for coffee to cool down (optional but practical!)
Remember: computers need every single step explicitly stated.
Task 3: Daily Life Algorithm
Think of something you do every day (brushing teeth, making breakfast, getting dressed). Write pseudo-code with at least 8 steps that a robot could follow.
Key Takeaways
- Programming is writing precise instructions for computers to follow
- Computers are literal — they do exactly what you tell them, nothing more
- All code eventually becomes binary (1s and 0s) that computers can execute
- The four building blocks of programming are: variables, conditions, loops, and functions
- Pseudo-code helps you plan your logic before writing actual code
- Programming is about solving problems and automating tasks
Resources
| Resource | Type | Difficulty |
|---|---|---|
| What is Programming? - Codecademy | Article | Beginner |
| How Do Computers Work? - Crash Course | Video Series | Beginner |
| Pseudocode Guide - Khan Academy | Tutorial | Beginner |