LESSON 1 OF 6 · 14 MINUTES
Values, names and a first local script
STEP 1 OF 6
Your objective
Run or trace a short script, distinguish a number from text, and explain why a calculated value does not automatically update.
STEP 2 OF 6
The idea
A program is a sequence of instructions. In this course, each displayed runnable example is a complete small script: start at the first line and proceed downward. Predict the output before running it; the difference between your prediction and the actual result is useful evidence, not a score.
For a local run, save only the code as a plain-text file such as first_steps.py. In a terminal already opened in that folder, try python3 first_steps.py; on a Windows installation the command may be py first_steps.py. Use the command your existing installation provides. Do not type these terminal commands at the Python >>> prompt, and do not copy expected-output lines into the file. If no interpreter is installed, trace the examples on paper; the course does not require an online service.
An integer such as 12 is a whole-number value. Text such as "minutes" is a string and needs quotation marks. The value 12 and the string "12" are different: 12 + 3 is 15, while "12" + "3" joins text to make "123". We use integers for all practice durations, avoiding fractional-number precision questions.
Assignment uses one equals sign. In total = sessions * minutes_each, Python first calculates the right-hand expression and then binds the name total to that result. It does not save a live spreadsheet formula. Changing sessions later does not recalculate total until the assignment is run again.
Use descriptive names with underscores and consistent spelling. print("Total:", total) displays a text label and a value separated by a space, then ends the line. A line beginning with # is a comment for the reader. If you see NameError, check whether you used a name before assigning it or spelled it differently; the final error line and reported location are clues.
STEP 3 OF 6
A fictional practice plan changes
Starting point
The plan starts with three sessions of 12 minutes. A fourth session is added after the total has already been calculated. Will the earlier total change by itself?
A checkable approach
sessions = 3 minutes_each = 12 total = sessions * minutes_each sessions = 4 print("Stored total:", total) total = sessions * minutes_each print("Recalculated total:", total)
Output is Stored total: 36 followed by Recalculated total: 48. The first multiplication happened while sessions was 3. Repeating the multiplication after the new assignment produces 48. The labels are strings; total is an integer.
STEP 4 OF 6
Try it yourself
Create a script with pages = 5 and minutes_each = 7. Calculate total, then change pages to 6. Print the old total, recalculate it and print the new total. Predict both outputs first. In a separate sentence, explain why printing "total" is different from printing total. Keep the prediction and correction in your own notes.
Fictional exercise · prewritten feedback, no live AI grading.
Write your answer on paper or in your own notes, then compare the options and worked answer.
Practice options
A. Both prints show 42 because total is linked permanently to pages.
Assignment is not a permanent formula link. The first result stays 35 until the calculation is run again.
B. The first print shows 35 and the second 42; quoted "total" would print the word.
Correct. Five times seven is stored first, then six times seven is stored. Quotes make literal text, not a lookup of the variable.
C. Changing pages produces an error because variables cannot be reassigned.
Reassignment is allowed. The question is when each expression is evaluated, not whether the name can receive a new value.
STEP 5 OF 6
Worked answer & self-check
Worked code: pages = 5 minutes_each = 7 total = pages * minutes_each pages = 6 print("Before recalculation:", total) total = pages * minutes_each print("After recalculation:", total) print("total") Expected output: Before recalculation: 35 After recalculation: 42 total Trace: after line 3, total is 35. After line 4, pages is 6 but total remains 35. Line 6 replaces total with 42. The last print receives literal text, so it does not look up a variable. If your first prediction was 42 twice, revise it by writing the current values beside each assignment. Each run begins from the top of this complete script.
Compare your answer
- Predicts 35 and 42 before checking, or records and explains a corrected prediction.
- Keeps the recalculation after the changed pages assignment.
- Distinguishes a quoted string from an unquoted name.
- Can identify the terminal command, source code and displayed output as three different things.
Give yourself one check for each point your work meets. Revise any missing piece. This is a self-check, not a score sent to a teacher.
STEP 6 OF 6
Recap & next step
- A name refers to the result assigned at that moment.
- Quotes mark text; unquoted names are looked up.
- Predict, run and trace the first point of disagreement.
Keep your working script. Next, make the program select different messages from different values.