FreeCampus Python

Meet Python Through a Tiny Program

Run a complete three-line Python program, connect source lines to exact output, make a controlled change, and repair a first syntax error.
python-foundations get-started first-program interpreter
Open in Colab
  • Level: Beginner · no programming experience assumed
  • Estimated time: 2–3 hours
  • You will learn: Distinguish source code, the Python interpreter, output, and an error by running and repairing a tiny complete program.
  • Practice in: Google Colab, JupyterLab, or a local editor

Your Python Learning Lab begins with something observable: three lines of source code that should produce three exact lines of output. You will not study every symbol formally yet. You will learn enough to run the program, follow its order, and make one defensible change.

NoteQuestions to answer
  • What is the difference between a program, source code, Python, and the Python interpreter?
  • Which source line produces each output line?
  • What does Python do when it reaches an instruction it cannot read?
  • How can one small edit create a predictable change?
  • What evidence should you preserve when the first run fails?

1. Give Python one complete instruction

A program is a set of instructions for a computer. Source code is the text in which those instructions are written. Python is the language used here; the Python interpreter is software that attempts to run Python source code.

Start with one instruction:

print("Python Learning Lab")

Predict before running: what text will appear, and will the quotation marks be part of the displayed result?

Expected output:

Python Learning Lab

The source contains more than the output:

  • print asks Python to display a value;
  • ( and ) enclose what will be supplied to print;
  • the quotation marks mark the beginning and end of text in the source; and
  • Python Learning Lab is the text value displayed.

The quotation marks help Python read the source. They are not part of this output. Unit 1 studies the words and symbols in much more detail, and Unit 2 studies text values. For now, recognize the complete visible shape print("message").

Try three valid messages separately:

print("Ready")
print("Ready for Python")
print("Ready: tools checked")

Spaces and punctuation inside the quotes belong to the message. Compare the exact outputs rather than saying only that each example “worked.”

2. Follow instructions from top to bottom

Now run the first Learning Lab program:

print("Python Learning Lab")
print("Status: ready")
print("Next step: predict before running")

Write all three predicted output lines before executing it. Python normally attempts this short script from the first visible instruction to the last:

Source position Instruction’s message Expected output position
1 Python Learning Lab 1
2 Status: ready 2
3 Next step: predict before running 3

Expected output:

Python Learning Lab
Status: ready
Next step: predict before running

Trace each source instruction through the interpreter to its output line.

flowchart LR
  A[Source line 1] --> D[Python interpreter]
  B[Source line 2] --> D
  C[Source line 3] --> D
  D --> E[Output line 1]
  D --> F[Output line 2]
  D --> G[Output line 3]

Reorder the source deliberately:

print("Next step: predict before running")
print("Python Learning Lab")
print("Status: ready")

The messages did not change, but the order did. Predict the complete output. Then run and check line 1, line 2, and line 3 separately. “The same text appeared” is incomplete evidence because order is part of the behavior.

Checkpoint: connect source to output

3. Read code and output as different records

A common beginner mistake is to copy the output back into a code cell:

Python Learning Lab
Status: ready

Those lines are useful output, but they are not the original Python instructions. Keep each kind of record in its proper place:

print("Python Learning Lab")
print("Status: ready")
Python Learning Lab
Status: ready

In a notebook, code belongs in a code cell and an explanation or copied result belongs in a Markdown cell. In a .py file, keep the Python source in the file and observe output in the terminal. Lesson 4 develops the notebook distinction.

Another misleading record shows source and guessed output without a label:

print("Status: ready")
Status: ready

A future reader cannot tell whether the second line was observed or merely predicted. A better learning note is explicit:

Source: print("Status: ready")
Prediction: Status: ready
Observed output: Status: ready

When prediction and observation match, preserve both. Matching evidence is still evidence. When they differ, do not edit the old prediction to pretend it matched; the difference tells you what to investigate.

4. Make one controlled change

Return to the understood program:

print("Python Learning Lab")
print("Status: ready")
print("Next step: predict before running")

Change only ready to checked:

print("Python Learning Lab")
print("Status: checked")
print("Next step: predict before running")

Before running, identify every expected downstream effect:

  • output line 1 should remain unchanged;
  • output line 2 should change from Status: ready to Status: checked; and
  • output line 3 should remain unchanged.

This is a controlled change: one source difference gives you a clear claim to check. Contrast it with this edit:

print("Learning Station")
print("Status: checked")
print("Next action: open Unit 1")

This program is valid, but all three messages changed. If the output surprises you, there are three possible source changes to inspect. Large changes are sometimes necessary; they are simply weaker experiments when you are learning one relationship.

Checkpoint: predict a controlled edit

5. Let the first error narrow the repair

Python must be able to recognize the source before it can follow the instructions. This example begins a text value with " but never closes it:

print("Status: ready)

Run it only after predicting that it will fail. The exact wording and caret may vary by Python version and environment, but the evidence will identify a SyntaxError and point near the unfinished text. Python is not saying your idea is bad. It is saying the source does not form a complete readable instruction.

Use a four-part first-error record:

Record Example
Source attempted print("Status: ready)
Observed evidence SyntaxError near the unfinished text
Smallest hypothesis The opening quote has no matching closing quote
One repair Add " after ready and rerun

The repair is:

print("Status: ready")

Do not make unrelated edits before checking it. If you also rename the message, move the line, and replace punctuation, you will not know which edit repaired the readable shape.

A second case has balanced quotes but no closing parenthesis:

print("Next step: predict before running"

Pair the visible delimiters:

  1. opening parenthesis ( needs closing parenthesis );
  2. opening quote " already has closing quote ";
  3. therefore add only the missing ).
print("Next step: predict before running")

A third case is valid Python but has an unintended message:

print("Status: raedy")

It runs and displays Status: raedy. No syntax error can detect that spelling contradicts your intention. Compare output with the stated expectation, locate the first difference, change only the text, and rerun:

print("Status: ready")

This distinction matters throughout programming: a run can succeed while the result is wrong for the task.

6. Preserve the evidence someone else needs

“Python does not work” is hard to investigate. A useful help request preserves:

  • the environment, such as Colab or a local terminal;
  • the complete smallest source that demonstrates the problem;
  • the exact command or action used to run it;
  • the complete output or error text;
  • the result you expected; and
  • the one repair already attempted.

For this source:

print("Python Learning Lab")
print("Status: ready)
print("Next step: predict before running")

an effective note is:

Environment: Google Colab code cell
Expected: three output lines
Observed: SyntaxError while reading line 2
Smallest clue: line 2 opens text but does not close it
Next check: add the closing quote on line 2, then rerun unchanged lines 1 and 3

You do not yet need to understand a full traceback. Unit 8 teaches error and traceback diagnosis systematically. Here, learn to preserve exact evidence and repair the earliest visible incomplete instruction.

Checkpoint: repair the earliest failure

7. Lab: create first_run.py

Create a folder named python-learning-lab. In Colab, you may place the source in one code cell now and download a .py copy after it works. Locally, create first_run.py inside the folder.

Your contract is exact:

Python Learning Lab
Status: ready
Next step: predict before running

Complete these stages:

  1. Write the three print(...) instructions.
  2. Before running, copy the expected output into your learning notes.
  3. Run the program and compare all three lines and their order.
  4. Change only ready to checked; predict that only line 2 changes.
  5. Observe the changed run, then restore ready.
  6. Remove one closing quote deliberately, run once, and preserve the error.
  7. Restore the quote and prove the original three-line output again.
ImportantObservable completion checks

Your final source has three complete calls. A clean run displays the three contract lines in order. Your notes contain the original prediction, the controlled-change prediction and result, and one error-and-repair record.

Hint: pair the visible shapes

Each line has print(, an opening quote, message text, a closing quote, and ). Compare one incomplete line with a complete line character by character.

Show one possible solution path

Create this final file:

print("Python Learning Lab")
print("Status: ready")
print("Next step: predict before running")

Run it once unchanged. For the controlled experiment, make a copy or preserve the original result, replace only ready with checked, and rerun. Restore ready. For the repair record, remove only the quote after ready, capture the resulting SyntaxError, replace the quote, and rerun from the complete source.

Key points

  • Source code is the program text; output is evidence produced by running it.
  • The Python interpreter attempts complete instructions in visible order.
  • Quotation marks and parentheses belong to the readable source shape even when they do not appear in output.
  • One controlled edit supports a precise prediction about what should change and what should remain stable.
  • A successful run can still produce the wrong result for the requirement.
  • Preserve the smallest source, exact action, observed evidence, expectation, and one attempted repair when you need help.

References

Back to top