Understand the idea
Start with a real question
You plan to study for five days, thirty minutes a day. That sounds simple until someone changes the plan to six days and the displayed total still says 150. Has Python forgotten how to multiply? No. The program is doing exactly what its instructions say, and this lesson will show you how to see it.
We will build a tiny study-time calculator and keep each decision visible. You will name the inputs, calculate a result and print it. Then you will change the plan and investigate why an earlier result does not update automatically. This is a better foundation than memorising a page of syntax without knowing when an instruction runs.
Keep a prediction beside the editor. Before each run, decide which values exist and what each print call should display. When the result surprises you, stop at that point. Finding the reason is the learning, not an interruption to it.
Understand the idea
A program is a sequence of instructions
Python lets you express calculations and other operations as readable instructions. The interpreter reads and executes a program according to the language's rules. Small programs are useful because you can predict each instruction's effect and compare that prediction with the actual result.
The practice editor runs Python through Pyodide inside an isolated browser runtime. These examples need only the bundled interpreter. They do not need package installation, external network access or persistent files. Later lessons will explain the standard library and distinguish portable language exercises from programs needing additional services.
See how it works
Example 1: print strings
PYTHON exampleRead the code, then try a change.
Try this example
print("Learning Python")
print("Predict before you run")
Expected output:
ReferenceCompare this with the explanation.
Learning Python
Predict before you run
The quoted text is a string. print receives the value inside its parentheses and writes it to the output panel. In this example each call ends its output with a newline, so the messages occupy separate lines. The quotes identify the string in source code but are not part of the printed message.
You can use either matching single quotes or matching double quotes for these simple strings. Start and finish a string deliberately; an unmatched quote causes a syntax error. Copying a sentence from a word processor can introduce typographic quotation marks that are not the ordinary source-code delimiters shown here.
See how it works
Example 2: numbers and strings are different values
PYTHON exampleRead the code, then try a change.
Try this example
print(10 + 5)
print("10" + "5")
print(10 * 5)
Expected output:
ReferenceCompare this with the explanation.
15
105
50
The first line adds numbers. The second joins strings; adding quote marks changes the kind of value the program is working with. The third line multiplies numbers using *. Python evaluates the expression before passing its result to print.
Do not guess a value's type merely from the characters displayed in output. A printed string containing digits can look like a printed number. Later lessons use explicit type inspection and conversion to make that distinction visible. For now, read the source and identify which values have string delimiters.
See how it works
Example 3: calculate with named values
PYTHON exampleRead the code, then try a change.
Try this example
price = 90
quantity = 4
total = price * quantity
print(total)
Expected output:
ReferenceCompare this with the explanation.
360
The equals sign is assignment: it binds the name on the left to the value calculated on the right. It does not ask whether two things are equal. The first two lines establish inputs, the third calculates a result, and the final line displays that result.
Names are case-sensitive. quantity and Quantity are different names. Choose clear names and use them consistently. Python does not require a dollar sign or a const keyword for these assignments. We will investigate names, changing values and object behaviour in more depth in subsequent lessons.
Understand the idea
Reason about execution order
If you change quantity to 5 before the total assignment, the product becomes 450. If you add quantity = 5 after the total assignment, printing the existing total still gives 360: the earlier calculation is not a spreadsheet formula that automatically recalculates whenever another name changes.
To calculate using the new quantity, execute the multiplication assignment again. Predict this behaviour, edit one example and verify it. Understanding execution order is more valuable than memorising the sample numbers.
Spot the mistake
Mistakes and independent practice
Check matching parentheses and quotes when a syntax error occurs. Check spelling and execution order when a name is not defined. Do not indent every line randomly: indentation has a structural role in Python, which we will study with conditional statements and loops. The top-level statements in this lesson start at the left margin.
Write a program that names a number of study days and a number of minutes per day, calculates total minutes and prints both a label and the result. Use only assignments, multiplication, strings and print.
Show hint Calculate total_minutes = study_days * minutes_per_day after assigning both input names.
Show solution For study_days = 5 and minutes_per_day = 30, the multiplication gives 150. A separate print("Planned study minutes") call can label the number printed by print(total_minutes).
Understand the idea
A named result is not an automatically updating formula
Execution order is one of the most useful mental models for a beginner. Python evaluates an assignment when it reaches that instruction. A total calculated earlier does not automatically update just because a different input name receives a new value afterwards. That behaviour is different from a spreadsheet cell that contains a continuing formula. You must execute the calculation again when you need a new result. Trace this distinction carefully before introducing loops or functions, because those later tools still rely on the same execution model.
Understand the idea
Slow down at the important part
Your turn
Build a picture of the program's state
Think of a name as a way for the program to refer to a value. When study_days receives 5, a later expression can use that name instead of repeating the literal. The name helps a reader understand the purpose of the number, but Python still follows the actual instructions rather than interpreting what the name sounds like.
Read an assignment from the right-hand side first. Work out the expression's value using the names available at that moment. Then connect the name on the left to that result. If an input name has not been assigned yet, there is no earlier value for that expression to read. Moving the input assignments above the calculation fixes the execution order; renaming the output label does not.
Understand the idea
Why an old total can be correct and outdated
After calculating five times thirty, total_minutes refers to 150. Changing study_days to 6 later changes that name's value. It does not travel backwards and rerun the multiplication. The old result is correct for the calculation that actually happened, even though it is no longer the result you want for the new plan.
You can repair this deliberately: calculate total_minutes again after changing the input. Compare the output before and after that second assignment. Name the instruction responsible for the difference. This distinction will help you understand functions, loops and events later, because those tools also execute instructions in an order.
Understand the idea
Ask the value the right kind of question
A string containing digits and a number can print similar characters. However, quotation marks change the value you give the program. Joining two strings is not the same operation as adding two numbers. To understand an output, inspect the source values and the operator rather than deciding from the appearance of the output alone.
Do not try to memorise every type in the language today. Start with a narrower skill: recognise the quoted strings and unquoted numbers in these examples, predict the operation, and explain whether the result is calculated or assembled as text. The next lesson will make type inspection and conversion explicit.
Your turn
Build it, change it, explain it
Build the study planner in checkpoints. First print a heading. Next assign the two numeric inputs. Calculate their product in a third name, then print that result. For five days of thirty minutes, the result should be 150, but explain the multiplication instead of treating 150 as a magic expected answer.
Try zero study days, then six study days. Predict each result before you change the source. Return to the original plan, calculate its total, and only then change study_days. Print the stored total, recalculate, and print again. Write one sentence explaining why those last two outputs differ.
Finally, create a mistake you can recognise: change the capitalisation of one variable reference. Observe the name error, restore the matching spelling, and run again. You now have a concrete debugging example: the printed label was not the problem, and Python did not guess that two differently spelled names meant the same thing.
Understand the idea
What this makes possible
You can now explain a program as a sequence rather than a mysterious result. Next, we will investigate why a value that looks like 12 might still behave like text. Keep your study calculator: it gives type conversion a real purpose instead of presenting it as another isolated command.