Python module 1: install, write, react
Fourteen sessions to start from absolute zero: install the tools, display your first message, store values, make the machine compute, ask it questions and let it make decisions. One new idea per session, every term defined, every exercise with a visible result on screen. Method: 20 minutes of theory, 30 of practice, 10 of recap.
Day 1 — Install Python and open the terminal
Goal: install Python 3.12+, open a terminal, and check that the python --version command answers.
Theory (20 min)
A program is a sequence of instructions written in a text file, handed to the machine to execute. Python is an interpreted language: a program called the Python interpreter reads your file line by line and does what it says, immediately. No compilation, no intermediate step.
The terminal (also called console or command prompt) is a window where you talk to the computer by typing text instead of clicking. You type a command, press Enter, and the machine answers in text right below. That is where you will run all your programs.
- On Windows: install Python from python.org/downloads and tick "Add python.exe to PATH" on the first screen. PATH is the list of folders where Windows looks for commands; without that box, the terminal will not find
python. Then open "Terminal" or "Command Prompt". - On macOS: open the Terminal app, then install Python from python.org. The command will be
python3. - On Linux: Python is almost always preinstalled, as
python3. If the command is missing, install thepython3package of your distribution.
The version matters: this path assumes Python 3.12 or newer. The number reads "major.minor.patch": 3.12.4 is version 3, sub-version 12, fourth fix.
Practice (30 min)
- Install Python as explained above for your system.
- Open a terminal. Type
python --version(on macOS/Linux:python3 --version) then Enter. - Success criterion: the terminal prints something like
Python 3.12.4or newer. If you see "command not found" or "is not recognized", rerun the installer with the PATH box ticked, close the terminal and open a new one. - Now type
pythonalone (orpython3): you enter the REPL, Python's conversation mode (the>>>prompt appears). Type2 + 2, Enter: it answers4. Typeexit()to leave. - Write down in the notebook: your system, the command that works (
pythonorpython3), the installed version. You will use this command every day — in this path we writepython; adapt if your machine wantspython3.
Agent tips: an LLM agent diagnoses an install problem in one question: "here is what python --version prints: [pasted output], what is wrong?". Trap: it cannot see your screen, paste the exact output. Proof to demand: the command that shows it is fixed, not an explanation.
Recap (10 min)
Three lines: what the interpreter is, what the terminal is, what PATH is. Then, without notes: close the terminal, reopen it, and find the Python version again.
Day 2 — Your first program
Goal: write a .py file in the editor, run it from the terminal, and see your message on screen.
Theory (20 min)
Yesterday you typed orders one by one in the REPL. Today we write them in a file so we can keep and replay them. A Python file is a plain text file whose name ends in .py.
The first instruction to know is print(): it displays something on screen. Between the parentheses goes what you want to display. A piece of text is written between quotes — it is called a string:
print("Hello world")
The quotes are not displayed: they only tell Python "this is text, not an instruction". print(Hello) without quotes would be an error, because Python would look for something named Hello.
The editor + terminal pair is your workshop: you write and save in the editor, you run in the terminal with python file_name.py. The terminal runs the command in the current directory — the folder it is "standing in". The cd command (change directory) moves around: cd Documents\python on Windows, cd Documents/python on macOS/Linux.
Practice (30 min)
- Create a
pythonfolder in your Documents. In the terminal, move into it withcd. - Open your editor, type exactly:
print("Hello world")
print("I am coding.")
- Save it as
hello.pyin that folder (careful: nothello.py.txt— if Windows hides extensions, show them in the Explorer options). - In the terminal:
python hello.py. - Success criterion: both lines appear in the terminal, without the quotes.
- Change the text, save, rerun with the Up arrow (it recalls the last command). See the change: you have just looped through write → save → run, a cycle you will repeat hundreds of times.
- Break it on purpose: remove the closing quote, rerun, read the message, fix it.
Agent tips: "create a hello.py file that prints two sentences" is an order an agent executes in a second. Trap: it may write it in a different folder than yours. Proof to demand: ls hello.py (or dir hello.py) plus the output of python hello.py, both pasted.
Recap (10 min)
Three lines: what print does, why the quotes, what the current directory is. Then, without notes: recreate hello.py from memory and run it.
Day 3 — Variables: labelled boxes
Goal: store a value in a variable, reuse it, change it.
Theory (20 min)
A variable is a name that points to a value. Picture a box with a label: the label is the name; the content is the value. You create the box with the = sign:
name = "Alice"
age = 30
print(name)
print(age)
name = "Alice" reads "name receives Alice". Beware: Python's = is not the maths one, it is an assignment — it puts the right-hand value into the left-hand name. After that, wherever you write name, Python reads the value stored in it.
Naming rules: lowercase letters, digits (not in first position) and the underscore _; no spaces. Python's convention is snake_case: last_name, coffee_count. A well-chosen name makes a program readable: total beats x.
A variable can change content: the box keeps its label, you replace the content.
score = 0
score = score + 10
print(score)
Prints 10: Python first computes score + 10 with the old value (0), then stores the result back into score.
After a = 5 then a = a + 2, what is a?
- 5
- 7
- An error: you cannot reuse a in its own assignment
Answer
7: Python evaluates the right side with the old value, then stores the result under the same label.
Which variable name is forbidden?
- 2nd_place
- second_place
- place_2
Answer
A name cannot start with a digit.
Practice (30 min)
- Create
profile.py:
name = "Alice"
city = "Lyon"
birth_year = 1994
age = 2026 - birth_year
print(name)
print(city)
print(age)
- Run it. Success criterion: three lines appear, the last one being the age computed by the machine, not by you.
- Replace the values with yours, rerun.
- Make
birth_yearwrong by one year, rerun, watch the age follow: a variable propagates its value wherever it is used. - Write a forbidden name (
2nd_place = 1), run, read the error, fix it.
Agent tips: ask it to "proofread this file and list the variables with what they hold at print time". Trap: it can "run it in its head" and get a reassignment wrong. Proof: you run the file yourself and compare line by line.
Recap (10 min)
Three lines: assignment vs equality, naming rules, why reusing a variable in its own assignment works. Redo profile.py without notes.
Day 4 — Numbers and calculations
Goal: tell integers from decimals, and make Python compute like a calculator.
Theory (20 min)
Python knows two kinds of numbers: integers (int, like 7, -3, 1000000) and floating-point numbers (float, like 3.14, -0.5 — with a dot, not a comma: the comma has another meaning in Python). The type of a value is its nature; it decides what you can do with it. The type() function tells you: print(type(7)) prints <class 'int'>.
The operations:
+addition,-subtraction,*multiplication;/division — always yields a float:10 / 2gives5.0;//floor division:10 // 3gives3(the remainder is dropped);%remainder of the division ("modulo"):10 % 3gives1;**power:2 ** 10gives 1024;- parentheses set the order:
(2 + 3) * 4gives 20,2 + 3 * 4gives 14.
Modulo is the programmer's favourite: n % 2 is 0 if n is even, 1 if odd. And one quirk to know: 0.1 + 0.2 prints 0.30000000000000004. Floats are stored in binary and some decimal values have no exact binary writing — like 1/3 in decimal. For money, count in cents with integers.
What is 10 / 2 in Python?
Answer
5.0: the / division always yields a float, even when it comes out even.
What is 7 % 3?
Answer
1: 7 = 2 × 3 + 1.
Practice (30 min)
- In the REPL (type
pythonalone), compute:365 * 24(the hours in a year),2 ** 16,100 // 7,100 % 7,(12 + 8) / 2. - Check
type(10 / 2)thentype(10 // 2). - Create
budget.py:
salary = 2100
rent = 750
groceries = 380
left = salary - rent - groceries
per_day = left / 30
print(left)
print(per_day)
- Success criterion: the program prints
970then about32.33— two numbers computed by Python. - Change the salary, rerun: both lines follow.
Agent tips: "compute X for me" is the worst use of an LLM: they make arithmetic mistakes. A serious agent writes the calculation in Python and runs it. Proof to demand: the command it ran and its output, never the result "from its head".
Recap (10 min)
Three lines: int vs float, what / always returns, what % is for. Without notes: how many whole weeks and remaining days in 100 days? (Write both expressions, check in the REPL.)
Day 5 — Text: strings
Goal: assemble and format text with f-strings.
Theory (20 min)
A string is text between quotes: "Alice", "12 Lilac Street", "123" (text, not the number 123!). You can glue them end to end with + — concatenation:
name = "Alice"
message = "Hello " + name
print(message)
But gluing pieces with + quickly becomes unreadable, and numbers must be converted by hand. The modern way is the f-string: an f right before the quote, and curly braces {} in the text where Python inserts the values:
name = "Alice"
age = 30
print(f"{name} is {age} years old.")
print(f"In 10 years, {name} will be {age + 10}.")
Between the braces you can put any expression — even a calculation. This is the standard way to write text in Python today.
A few string tools (they are called methods: actions you ask of a value with a dot):
len("Alice")→ 5: the length, in characters;"Alice".upper()→"ALICE",.lower()→"alice";" abc ".strip()→"abc": trims spaces at the edges;"a,b,c".split(",")→ the list["a", "b", "c"](lists come in module 2).
What is "3" + "4"?
- 7
- An error
- The string "34"
Answer
These are two pieces of text: + concatenates them, there is no addition.
In f"Total: {price * 2}", what do the braces do?
- They insert the result of the calculation into the text
- They print the text {price * 2} as-is
- They convert the text to a number
Answer
The f-string evaluates the expression inside the braces and inserts the result.
Practice (30 min)
- Create
card.py:
name = "Alice"
city = "Lyon"
age = 30
print(f"My name is {name}.")
print(f"I live in {city}, {len(city)} letters.")
print(f"Next year I will be {age + 1}.")
print(name.upper())
- Success criterion: four sentences appear with your values inserted — no brace stays visible on screen.
- Forget the
fbefore a string, rerun: the braces print as-is. This is the number one beginner mistake — learn to recognise it. - Add
print("Hello " + name + ", you are " + str(age)): notice the mandatorystr()to convert the number, and why the f-string is more comfortable.
Agent tips: "turn these three +-style prints into f-strings" is a perfect refactor for an agent. Trap: it may change the displayed text along the way. Proof: run both versions and compare outputs character by character.
Recap (10 min)
Three lines: concatenation, f-string, what len() does. Without notes: print "Alice is 30 years old" from two variables, with an f-string.
Day 6 — Asking the user: input()
Goal: write a program that asks a question and uses the answer.
Theory (20 min)
So far your programs always said the same thing. input() makes them interactive: the program stops, shows a prompt, waits for the user to type something and press Enter, then returns what was typed:
name = input("What is your name? ")
print(f"Hello {name}!")
Today's critical point: input() always returns a string, even if the user types digits. Type 25, you get the text "25", not the number. And "25" + 1 is an error: you cannot add text and a number.
The solution: convert with int() (to an integer) or float() (to a decimal):
age = int(input("Your age? "))
print(f"In ten years: {age + 10}")
If the user types "thirty", int("thirty") crashes with a ValueError. We will learn to catch it on day 26; today, type digits.
The user types 12 at answer = input("? "). What is answer + 3?
- 15
- A TypeError
- The string "123"
Answer
answer is the string "12"; adding the number 3 to text raises a TypeError. Convert first with int(answer).
Practice (30 min)
- Create
dialogue.py:
name = input("Your first name? ")
city = input("Your city? ")
year = int(input("Your birth year? "))
age = 2026 - year
print(f"Hello {name} from {city}, you are about {age}.")
- Success criterion: the program asks three questions, waits for your answers, then prints a sentence that uses all three.
- Remove the
int(...), rerun, read the TypeError:unsupported operand type(s) for -: 'int' and 'str'. Put it back. You can now read the most common beginner error. - Add a fourth question ("your favourite dish?") and weave the answer into the final sentence.
Agent tips: paste your complete TypeError plus the line that produces it, and ask "why, in one sentence". Trap: without the code line, it guesses. Proof: its fix must run on your machine, not in its reply.
Recap (10 min)
Three lines: what input does, what it always returns, when to convert. Without notes: a program that asks for a number and prints its double.
Day 7 — Reading an error message without panicking
Goal: recognise the three most common beginner errors and know where to look in an error message.
Theory (20 min)
When Python cannot understand, it stops and prints an error message. That message is not a punishment: it is an instruction manual. Read it bottom to top: the last line gives the error type and the cause, the lines above show where it happened (file, line number, and a caret ^ under the exact spot).
The three errors you will meet most:
- SyntaxError: the sentence is malformed — a forgotten parenthesis or quote, a typo on a keyword. Example:
print("hello→SyntaxError: unterminated string literal. The caret points where Python got lost. - NameError: you use a name that does not exist — a typo in a variable, or a variable used before it is created.
NameError: name 'socre' is not definedreads "I do not know socre". Check the exact spelling, capitals included. - TypeError: you mix two incompatible natures, like text and a number in a calculation (seen yesterday). The message names both types involved.
The method, always the same: read the last line, spot the line number given, open the file at that line, fix, rerun. A fixed error is a learned lesson; write it in the notebook with its cause.
NameError: name 'score' is not defined. Most likely cause?
- A typo on the name, or the variable is created below its use
- A forgotten quote
- A number in place of text
Answer
NameError always means an unknown name: spelling or line order.
Where is the most useful part of an error message?
- At the very top
- In the middle
- At the very bottom: the type and the cause
Answer
Read a Python message bottom-up: the last line sums it all up.
Practice (30 min)
- Create
errors.pywith this deliberately broken content:
name = "Alice"
print(naem)
age = int("thirty")
- Run it, read the NameError, note the line number, fix
naemtoname. - Rerun: a new error, a ValueError on
int("thirty"). Read its last line. Replace withint("30"). - Add the line
print("end"(missing parenthesis), rerun: SyntaxError. Fix it. - Success criterion: the final file runs without errors, and your notebook lists the three errors met, with their cause in one sentence each.
Agent tips: an agent excels at translating an error message into plain language: paste the WHOLE message plus the file. Trap: paste only the tail — it would have the cause but not the context. Proof: after its fix, you rerun and the error is gone.
Recap (10 min)
Three lines: how to read an error message, and today's three types with their typical cause. Without notes: write a deliberate NameError and fix it.
Day 8 — True or false: booleans and comparisons
Goal: compare values and handle the two values True and False.
Theory (20 min)
Before a program can decide (tomorrow), you must know how to ask it questions. A comparison is a question whose answer is true or false:
==: equal? (two = signs! A single = stores a value, two == compare. This is THE classic typo.)!=: different?<,>,<=,>=: smaller, greater, at most, at least.
The answer to a comparison is a boolean (after the mathematician George Boole): a value that can only be True or False — the third type you meet after numbers and strings. Mind the capitals: true in lowercase is a NameError.
age = 20
print(age >= 18)
print(age == 18)
is_adult = age >= 18
print(type(is_adult))
Prints True, False, then <class 'bool'>. You can store the result of a comparison in a variable, like is_adult here — that is what will make tomorrow's decisions readable.
Comparisons also work on text: "alice" == "Alice" is False (case matters), hence the reflex answer.lower() == "yes" to accept "Yes", "YES", "yes".
What is 5 == "5"?
- True
- False
- An error
Answer
False: a number never equals a string, even if they "look alike". No error: == simply answers False.
What does age = 18 (a single =) do?
- Stores 18 in the variable age
- Asks whether age is 18
- A syntax error
Answer
One = assigns; two == compare.
Practice (30 min)
- In the REPL, test:
10 > 5,10 == 10.0,"a" == "A",7 != 7,type(True). - Create
check.py:
word = input("A password to test: ")
long_enough = len(word) >= 8
has_digit = "0" in word or "1" in word
print(f"Long enough: {long_enough}")
print(f"Contains 0 or 1: {has_digit}")
- Success criterion: the program prints two True/False lines that change with what you type (try "abc", then "abcdef01").
inis new:"0" in wordasks whether the text contains that character. Add a test"!" in wordand a third printed line.
Agent tips: "explain the difference between = and == with an example that crashes": a good exercise to have an agent correct. Trap: inside a real condition, if age = 18: is an immediate SyntaxError — Python refuses, luckily. Proof: have it produce the example and the error, run both.
Recap (10 min)
Three lines: what a boolean is, = vs ==, what in does on a string. Without notes: a variable that is True when a number is even (hint: %).
Day 9 — if / else: the program decides
Goal: run code only when a condition is true.
Theory (20 min)
if runs a block of code only when its condition is true; the optional else takes over when it is false:
age = int(input("Your age? "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
print("End of program.")
Three things to see: the colon : at the end of the if and else lines; the block under the if is indented — shifted 4 spaces to the right, that is how Python knows what belongs to the if; and the last line, not indented, runs in all cases. Spaces are part of Python's syntax (session 11 for the details).
The condition is any expression that is True or False: a comparison, a boolean stored in a variable. You can also test a variable directly: if is_adult: reads "if is_adult is true".
A beginner trap: everything after an if must work in both cases. If you create a variable inside the if block and the condition is false, it will not exist afterwards. Initialise your variables before the if.
With age = 15, what does the lesson's program print?
- You are an adult.
- Nothing
- You are a minor. then End of program.
Answer
The condition is false: the else block runs, then the unindented line always runs.
What is missing in if age >= 18 (a line followed by an indented print)?
- The colon at the end of the line
- Parentheses around the condition
- Quotes around the condition
Answer
Without the colon, SyntaxError. Parentheses around the condition are not required in Python.
Practice (30 min)
- Retype the lesson's program into
adult.py, run it with 20 then with 15. - Success criterion: two runs give two different outputs, and "End of program." appears in both cases.
- Remove the indentation of the first print, rerun:
IndentationError. Fix it — that is the fourth error in your notebook. - Create
even.py: ask for a number, print "even" ifn % 2 == 0, "odd" otherwise. Test with 10 and 7. - Bonus: in
adult.py, storeage >= 18in a variableis_adultand writeif is_adult:. Same behaviour, better reading.
Agent tips: "add an else to this script that handles the empty case" — an agent does that well. Trap: it may reindent the whole file its own way. Proof: the program answers the same inputs the same way, plus the new case.
Recap (10 min)
Three lines: the role of the colon, the role of indentation, when else runs. Without notes: a program that says "positive" or "negative or zero" for a typed number.
Day 10 — elif, and, or: multiple decisions
Goal: handle more than two cases, and combine several conditions.
Theory (20 min)
When there are more than two cases, chain them with elif (a contraction of "else if"):
grade = int(input("Your grade out of 20? "))
if grade >= 16:
print("Excellent")
elif grade >= 14:
print("Good")
elif grade >= 10:
print("Pass")
else:
print("Fail")
Python tests the conditions in order, top to bottom, and stops at the first true one. With a grade of 17, only "Excellent" prints, even though 17 ≥ 10 is also true. So the order of cases matters: from most to least demanding. The final else catches everything left over.
To combine conditions: and (both must be true), or (at least one), not (inverts):
age = 25
has_licence = True
if age >= 18 and has_licence:
print("You can rent a car.")
if age < 12 or age >= 65:
print("Reduced fare.")
Precedence: not first, then and, then or. As soon as a combination has more than two terms, add parentheses to be sure: (a or b) and c.
With grade = 14 and the lesson's program, what prints?
- Excellent
- Good
- Pass
Answer
14 >= 16 is false, 14 >= 14 is true: "Good", and Python stops there.
True or False and False is…
- True (and binds before or: False and False = False, then True or False = True)
- False
- An error
Answer
and has priority over or: the expression is True.
Practice (30 min)
- Retype the grades program into
grades.py. Test 17, 14, 10, 5. - Success criterion: four runs, four different mentions.
- Swap two branches (put
grade >= 10first), test 17: "Pass" prints. That is why order matters. Restore it. - Create
cinema.py: ask the age; under 12 or 65 and over → "Reduced fare: €5"; student (also ask yes/no, compare with.lower() == "yes") → "Student fare: €7"; otherwise "Full fare: €10". Test all four paths.
Agent tips: "write the truth table of my conditions and tell me which case is never reached": an agent spots dead branches well. Trap: it sometimes assumes the order you "meant". Proof: run every branch with an input that triggers it.
Recap (10 min)
Three lines: what elif does, why the order of cases matters, and vs or. Without notes: rewrite the grades program with three branches.
Day 11 — Indentation: why spaces matter
Goal: understand indented blocks and never suffer an IndentationError again.
Theory (20 min)
In Python, indentation — the shift at the start of a line — is not decorative: it defines the structure of the program. Where other languages use braces {} to group instructions, Python uses the shift. All lines shifted to the same level after an if, an else (and later for, while, def) form a block.
if raining:
print("Take an umbrella.")
print("And a raincoat.")
print("Good luck.")
The first two prints form the if's block; the last one, back at the left edge, no longer belongs to it. The convention — shared by every Python project — is 4 spaces per level. Never mix tabs with spaces: visually identical, but Python may refuse the mix. Set your editor to "insert spaces for tabs" (VSCodium's default).
Blocks nest: an if inside an if adds 4 more spaces. Two levels are enough for most programs; beyond three, it is often a sign you can simplify.
if age >= 18:
if has_licence:
print("Rental possible.")
else:
print("Get your licence!")
else:
print("Come back in a few years.")
What is Python's indentation convention?
- 2 spaces
- 4 spaces
- A tab, mandatory
Answer
4 spaces per level, everywhere, never mixed with tabs.
In the second example, if age = 15, what do we see?
- Rental possible.
- Get your licence!
- Come back in a few years.
Answer
The first if is false: we go straight to its else, without looking at the nested if.
Practice (30 min)
- Retype the nested example into
rental.py, with both variables defined at the top. Test the four combinations (18+/licence, 18+/no licence, 15, 15/no licence). - Success criterion: four different messages for four situations.
- Shift one line by one extra space in the middle of a block, rerun: IndentationError. Read the indicated line, fix it.
- Rewrite the same program with elif and and, without nesting. Compare: which version do you reread faster? Keep that one.
Agent tips: "rewrite this nested code flat with elif" is a refactor an agent does cleanly. Trap: it may flip a condition along the way (≥ becomes >). Proof: your four-case table must give the same messages before and after.
Recap (10 min)
Three lines: what a block is, the 4-space rule, the danger of mixing tabs and spaces. Without notes: a two-level nested if that prints three possible messages.
Day 12 — Mini-project: the tip calculator
Goal: assemble variables, input, calculations, f-strings and if into a useful program.
Theory (20 min)
No new concept today: we assemble. A real small program always follows the same three-beat skeleton:
- Inputs: ask the user for what you need (input, conversions).
- Computation: turn those inputs into results (operations, conditions).
- Output: display the results, formatted (f-strings).
Two formatting tools useful for money:
round(x, 2)rounds to two decimals:round(12.345, 2)gives12.35.- In an f-string,
{price:.2f}prints the number with exactly two decimals:f"{12.3:.2f}"gives"12.30". Handy for prices.
Before coding, write the three beats on a draft (or in the notebook) in plain words: "I ask for the bill and the tip rate; I compute the tip and the total; I print both amounts". A program thought out in plain language almost writes itself in Python.
Practice (30 min)
- Write
tip.pyfollowing the skeleton:
bill = float(input("Bill amount (€)? "))
service = input("Service: great / ok / bad? ").lower()
if service == "great":
rate = 0.15
elif service == "ok":
rate = 0.10
else:
rate = 0.0
tip = bill * rate
total = bill + tip
print(f"Tip: {tip:.2f} €")
print(f"Total to pay: {total:.2f} €")
- Success criterion: with a bill of 42.50 and "great", the program prints
Tip: 6.38 €andTotal to pay: 48.87 €(floats sometimes round surprisingly — remember day 4). Check all three service levels. - Add a question "How many people?" and print the share per person (
total / people, still with:.2f). - What if the user types "GREAT"? Check that the
.lower()absorbs the case.
Agent tips: an agent writes this whole program in ten seconds from the three-beat description — which is exactly why we wrote it by hand: you must be able to proofread its version. Trap: it may pick rates different from yours. Proof: impose your three test amounts and compare outputs.
Recap (10 min)
Three lines: the inputs → computation → output skeleton, and the two ways to round a price. Without notes: rewrite the program with only two service levels.
Day 13 — Guided review
Goal: consolidate all of module 1 with short exercises, no new concept.
Theory (20 min)
Reread your notes from days 1 to 12, then the summary table:
| Notion | Shape | Example |
|---|---|---|
| Display | print(...) | print("hello") |
| Store | name = value | age = 30 |
| Ask | input(...) then convert | n = int(input("? ")) |
| Insert into text | f-string | f"{name} is {age}" |
| Compare | ==, !=, <, >= | age >= 18 |
| Decide | if / elif / else + indentation | if age >= 18: |
Find the row of the table you could least explain out loud: that is the session to reread in full. Learning is reviewing just as things start to fade — today is that moment for days 3 to 6.
print(f"2 + 2 = {2 + 2}") prints…
- 2 + 2 = {2 + 2}
- 2 + 2 = 4
- An error
Answer
The braces of an f-string evaluate the expression: 4.
input() always returns…
- A string
- A number if the user types digits
- A boolean
Answer
Always a string; converting with int() or float() is your job.
Which line is a SyntaxError?
- if age >= 18:
- age = age + 1
- if age >= 18
Answer
Without the colon, Python refuses the line.
Practice (30 min)
Four exercises, without rereading the sessions — check by rerunning each program:
- Guess the age: ask for first name and birth year, print "X will be Y this year". Criterion: the sentence uses both inputs and Python does the maths.
- Converter: ask for kilometres (float), print the miles (1 km ≈ 0.621371 mile) with two decimals. Criterion: 10 km → 6.21 miles.
- Banknotes: ask for an amount in euros, print how many €20 notes (with //) and what remains (with %). Criterion: 95 → 4 notes, remainder 15.
- Access: ask an age; under 13 "too young", 13 to 17 "with an adult", 18 and over "welcome". Criterion: three runs, three messages.
Agent tips: paste your four programs to the agent: "proofread them like a teacher, grade each out of 10, tell me the first thing to improve in each, do not rewrite them". Trap: it rewrites instead of correcting — forbid it explicitly. Proof: its remarks must quote your lines.
Recap (10 min)
Three lines: the hardest of the four exercises, and why. Redo "Banknotes" without looking.
Day 14 — Module 1 review
Goal: prove the module's skills with a complete program written alone, and prepare module 2.
Theory (20 min)
One last presentation tool before the review: comments. Everything after a # on a line is ignored by Python — it is written for humans, not for the machine:
# Inputs: the price and the quantity
price = float(input("Price? ")) # float because there may be cents
A good comment explains the why, not the what — the code already says what it does. # we add 1 above x = x + 1 is noise; # page numbering starts at 0 is information. Your module 4 programs will be reread in three weeks (by you): be kind to yourself.
And the reflex that changes everything from now on: write in small steps. Never write 30 lines at once. Write 4 lines, run, see them work, continue. A program that breaks after 4 new lines has its bug in those 4 lines.
Practice (30 min)
The review program, to be written alone, without copying the sessions: party.py, a party budget estimator.
- Ask: the number of guests, the total drinks budget, the total food budget.
- Compute: the total budget, the cost per guest.
- Decide: if the cost per guest exceeds €25, print "Tight budget: fewer guests or more money"; between €10 and €25, "Comfortable budget"; under €10, "Royal budget".
- Display everything with f-strings with two decimals, and comment the three beats (inputs / computation / output) with
#.
Success criterion: with 8 guests, €60 of drinks and €140 of food, the program prints a total of 200.00 €, a cost per guest of 25.00 € and "Comfortable budget" (25 is not strictly above 25 — pick your comparisons accordingly, that is on purpose). If you wrote the program without copying anything, module 1 is yours.
Agent tips: tempted to have an agent write it? Today is precisely the day not to. Ask it afterwards instead: "here is my program and my three test cases, find an input that makes my code say something silly". Trap: it sometimes invents one that is not — rerun the case yourself. Proof: a set of inputs + the observed output.
Recap (10 min)
Three lines: what a comment is for, the small-steps rule, and the point of the review that resisted you. Tomorrow: loops, or how to make the machine repeat without repeating yourself.
Found this useful? Tell us what to measure next.
Comments
No account, no tracker: a comment is read by a human before it appears.