How computers execute programs
Chapter 1 of 132 · Level 0 · Computer and logic foundations · Python demonstrations with recorded outputs. Learn through reading, predicting and testing real Python code.
Course disclaimer · independent educational content
01 · Why this concept matters
An input becomes a value in memory; the multiplication transforms the data, and print produces a visible result. This is the input-process-output model that underlies almost every program.
Learning goal: How computers execute programs. Start by reading what the program does, then inspect its exact output. Where an example illustrates only a prerequisite, study the named advanced feature separately before using it in production.
Before running the code below, install Python 3 from python.org. Open a terminal and run python3 --version on macOS/Linux or py --version on Windows. Create a plain text file named first.py, paste the example, save the file, then run python3 first.py (macOS/Linux) or py first.py (Windows). If the command is not found, check your Python installation and PATH before continuing.
02 · The important subtopics
Study these connected ideas as you work through the demonstration:
- Hardware versus software and CPU memory storage
- Operating systems applications and processes
- Source code interpreter and machine instructions
- Inputs transformations outputs and persistence
03 · Pinpoint: read the code line by line
- Line 1
input_items = 3Create, update, or use a value. Notice what values enter this statement and which names it affects. - Line 2
price_per_item = 4Create, update, or use a value. Notice what values enter this statement and which names it affects. - Line 3
total = input_items * price_per_itemCreate, update, or use a value. Notice what values enter this statement and which names it affects. - Line 4
print('Items:', input_items)Display a result. Notice what values enter this statement and which names it affects. - Line 5
print('Total:', total)Display a result. Notice what values enter this statement and which names it affects.
Find the literal input values and arguments, follow each operation in execution order, and verify the result below. This habit turns a code listing into a testable explanation.
04 · Runnable Python example and verified output
How computers execute programs: working demonstration
Python · runnableinput_items = 3
price_per_item = 4
total = input_items * price_per_item
print('Items:', input_items)
print('Total:', total)
Items: 3 Total: 12
Why it works: An input becomes a value in memory; the multiplication transforms the data, and print produces a visible result. This is the input-process-output model that underlies almost every program.
Worked example 2 · How Computers Execute Programs in practice
Python · executed and checkedsource = 'print(2 + 3)'
print('Source:', source)
exec(source)
Source: print(2 + 3) 5
Pinpoint learning: This practical how computers execute programs demonstration uses a small input you can inspect. Run it exactly as shown, compare the displayed result, then change one value and predict how the result will change.
Understand the code line by line
1: source = 'print(2 + 3)'— Store or update the value on the left using the expression on the right.2: print('Source:', source)— Display the value so you can compare it with the verified output.3: exec(source)— Execute this statement and observe its effect on later values.
05 · Independent practice and answer guidance
Exercise A · Adapt the code
Describe the input, processing rule, and output of a temperature converter.
Exercise B · Predict
Before pressing Run, predict the first displayed line. Next, change one literal value and record the new observed output. Explain the difference in one clear sentence.
Exercise C · Debug
Make a temporary invalid change, read the exception or failed assertion if one occurs, restore the working code, and explain the repair.
Worked explanation for the original example
An input becomes a value in memory; the multiplication transforms the data, and print produces a visible result. This is the input-process-output model that underlies almost every program.
Items: 3 Total: 12
06 · Build, verify and advance
Real-world task: Draw the execution path of a small calculator from keyboard input to display.
Run the original code; explain the important lines; change one input and verify the new outcome; use a test or recorded result to justify your conclusion.
