learn
Weeks 1–3 · About 30 hours

Telling the computer what to do

Storing information, making decisions, and repeating work. These three ideas sit underneath every program ever written.

Every algorithm later in this roadmap is loops and decisions underneath the surface. — one of the most famous there is — turns out to be a loop with two variables in it. If loops are still effortful for you, binary search will feel impossible. If loops are automatic, it will feel obvious. That difference is decided here.

Variables and types

A variable is a name you stick onto a piece of information so you can talk about it later. Types are the different kinds of information you can store.

Think of it likeA luggage tag. The tag is not the suitcase; it just lets you refer to the suitcase without carrying it around.

You write price = 20, and from then on the name price refers to the number 20. Later you can write price = 25 and the name refers to something else. Nothing is permanent.

There are four kinds of information you meet immediately. Whole numbers, called integers — 3, 100, -7. Numbers with a decimal point, called floats — 3.5, 0.001. Text, called strings, always written inside quotes — "hello". And true-or-false values, called booleans — written True and False, capitalised.

The important mental shift: a variable does not contain the value, it refers to it. This sounds like hair-splitting now. It becomes the single most important idea in the whole roadmap when you reach and trees from week 15 onwards, because those are built entirely out of things referring to other things.

Where you meet it in real softwareEvery program stores state — a user's name, a running total, whether someone is logged in. That is all variables.

Getting information in and out

print() shows something to the person using your program. input() asks them to type something and hands you back what they typed.

print("hello") puts hello on the screen. That is your main window into what your program is doing, and for the next few weeks it is also your main debugging tool — when something is wrong, print the value and look at it.

name = input("What is your name? ") shows the question, waits for typing, and stores whatever came back in name. One trap catches everyone: input() always gives you text, even when the person typed a number. If you need the number 5 rather than the text "5", you have to convert it with int().

f-strings are the tidy way to mix values into text. You write f"Hello {name}" and Python drops the value of name into the sentence. The f before the opening quote is what switches this on. Without it you get the literal characters {name}, which is a confusing first bug to hit.

Where you meet it in real softwareCommand-line tools, scripts that ask for a filename, and every early program you will write.

Operators — doing things to values

Symbols that combine or compare values: adding numbers, checking whether two things are equal, joining conditions together.

Arithmetic is what you expect: + - * / for add, subtract, multiply and divide. Two are less obvious and both matter enormously later. Double slash divides and throws away the remainder, so 7 // 2 is 3. And percent gives you only the remainder, so 7 % 2 is 1.

That percent operator looks like a novelty and is not. It is how you test whether a number is even, how clock arithmetic works, and — in week 17 — how a decides which storage slot to put something in. It shows up constantly.

Comparisons give back True or False: double equals for “is equal to”, exclamation-equals for “is not equal to”, and the usual less-than and greater-than signs for ordering. Note the double equals. A single equals assigns a value; a double equals asks a question. Mixing them up is the most common beginner typo in any language.

Logical operators join conditions: and needs both sides true, or needs at least one, not flips true to false. In Python these are written as those English words, not as symbols.

Where you meet it in real softwareValidation rules, pricing calculations, permission checks — anywhere a program has to decide something.

Conditionals — making decisions

if runs a block of steps only when something is true. elif offers another condition to try. else catches everything left over.

Think of it likeA flowchart. You arrive at a diamond, answer the question, and take one of the paths out.

The shape is: if age >= 18: followed by an indented block of steps. If the condition is false those steps are skipped entirely, as though they were not written.

elif lets you chain more questions, and Python checks them top to bottom, stopping at the first one that is true. else is the fallback with no condition attached. You can have as many elif branches as you like, and at most one else.

The most useful habit to build here is thinking about which branch runs when nothing matches. Beginners write the happy path and forget the else, so the program silently does nothing when something unexpected happens. That silence is much harder to debug than a crash would have been.

Where you meet it in real softwareLogin checks, discount rules, form validation, whether to show an error message.

Loops — repeating work

A for loop repeats once for each item in a collection, or a fixed number of times. A while loop repeats for as long as a condition stays true.

for item in things: runs the indented block once per item, with item referring to a different one each time. for i in range(5): runs it five times with i counting 0, 1, 2, 3, 4. Note that it starts at 0 and stops before 5 — that is deliberate, and it matches how positions in a list are numbered.

while condition: keeps going as long as the condition is true. It checks before each pass, so if the condition is already false, the block never runs at all. The risk with while is the infinite loop: if nothing inside ever makes the condition false, your program hangs forever. Press Ctrl+C in the terminal to stop it.

break exits the loop immediately, abandoning the rest of it. continue skips the rest of this one pass and jumps to the next. Both are useful, and both make code harder to follow if you scatter them, so use them only where they genuinely simplify things.

Choosing between the two: use for when you know the collection or the number of repeats up front. Use while when you are waiting for something to become true and do not know how long that will take.

What it costsA loop over n items is O(n) — the time grows in step with how many items there are. Put a loop inside another loop and you get O(n²), which gets slow alarmingly fast.

Where you meet it in real softwareProcessing every row of a file, retrying a failed network request, running a game until the player quits.

Indentation is not decoration

In Python, the spaces at the start of a line decide which block that line belongs to. Getting them wrong changes what your program does, or stops it running at all.

Most languages use curly brackets to mark where a block starts and ends. Python uses indentation instead — normally four spaces. Lines indented to the same depth belong to the same block.

This means a line indented one level too far quietly becomes part of the loop above it and runs many times instead of once. That is not a crash, it is wrong behaviour, which is harder to spot.

Let your editor handle it. VS Code indents automatically after a colon. Do not mix tabs and spaces — Python will refuse to run the file, and the error message is not especially clear about why.

Every beginner loses an hour to this exactly once. Knowing in advance that indentation is meaningful is most of the cure.

Where you meet it in real softwareIt is a permanent feature of reading any Python code, including everything in the roadmap ahead.

Reading about this stage is not the same as finishing it. Type every one of these from a blank file rather than copying — the writing is the part that teaches.

Temperature converter

Ask for a temperature in Celsius and print it in Fahrenheit. Then extend it to convert both ways. Exercises input, converting text to a number, arithmetic and printing.

FizzBuzz

Print the numbers 1 to 100, except: for multiples of 3 print Fizz, for multiples of 5 print Buzz, and for multiples of both print FizzBuzz. The classic first test of loops, conditionals and the remainder operator together. Order your conditions carefully — check for both before checking for either.

Number-guessing game

The program picks a secret number, the player guesses, and it replies higher or lower until they get it. Uses a while loop that keeps going until a condition is met. When you reach binary search in week 26, notice that the best guessing strategy is exactly that algorithm.

Multiplication table printer

Print a 12 by 12 times table as a neat grid. Needs a loop inside a loop — the outer one for rows, the inner one for columns. Your first taste of why nested loops are expensive.

Looping calculator

Ask for two numbers and an operation, print the result, then ask again — repeating until the user types quit. Combines input, conditionals and a while loop. Handle division by zero rather than letting it crash.

Exit checkYou can write FizzBuzz in a blank file, from memory, with no errors, in under five minutes. Not from a tutorial — from nothing.

If you cannot do this, repeat the stage rather than moving on. Nothing later gets easier by skipping it.

Worth knowing before you start

  • Type every example yourself rather than copying and pasting. The gap between understanding a video and writing code on a blank screen is the entire skill, and copying skips exactly the part that builds it.

This stage corresponds to Phase 0 — Core Syntax & Control Flow in the source roadmap.