NOETRION

Choose a topic

DAY 01 OF 30 · RUN AND REASON

Your first Python program

Run a script, trace expressions, interpret output, and repair your first error.

90–120 minutes suggested study timePython 3.12Not yet completed

Today's outcomes

  • Distinguish source code, execution, and output.
  • Explain comments and statement order.
  • Repair a small program using the error message.

Before you start: No previous lesson required.

Understand the concept

Source code, execution, and output are different things

A program is a set of instructions written in a language the interpreter can understand. Your source file contains those instructions. Running the file asks Python to execute them. Output is the information the running program chooses to display. Keeping these three things separate helps you diagnose an apparently empty screen: a file can contain valid calculations but never print their results.

Python is used for scripts, data work, web services, automation, and many other tasks. That range does not mean one month makes you an expert in every area. The goal of this course is narrower and observable: read small programs, explain their behavior, build several useful programs, and verify their results. The final day asks for evidence of those abilities.

Use an existing Python environment you already know: a terminal, VS Code, or a notebook. This course starts with execution rather than an installation walkthrough. In a terminal, save a file called day01.py and run python day01.py; some systems use python3 instead. In a notebook, place the Python code in a code cell and run that cell. Do not paste the terminal command into a Python cell.

An expression calculates; a statement performs an action

The expression 2 + 3 evaluates to the value 5. The statement print(2 + 3) evaluates that expression and displays its result. In an interactive interpreter or notebook, a final expression may be displayed automatically. An ordinary script does not automatically display every expression. Use explicit printing while learning so the same example is understandable in either environment.

Text inside quotation marks is a string. print("2 + 3") displays the characters 2 + 3, while print(2 + 3) displays a calculated number. Quotation marks therefore change the meaning of the expression, not just its appearance. Python evaluates the arguments inside the call before print displays them.

Order and comments make a program readable

For today's straight-line examples, execution proceeds from the first statement to the next. Each print call creates one output line by default. Several arguments inside one call are separated by spaces. Comments begin with # outside a string and continue to the end of the line. Python ignores their explanatory text, but future readers benefit from a comment that explains a decision.

Use comments for a purpose: “Seven days form a full week” explains why a calculation exists. A comment saying “print a number” merely repeats visible syntax. A # inside quotation marks is part of the string, so print("Issue #3") displays the hash character. Later lessons introduce branches, loops, and functions that change this simple execution order.

Worked example

Predict the exact three output lines before running this script. The // operator counts full groups and % gives the remainder for the positive integers used here; Day 4 examines both more closely.

print("Python challenge")
print("Days planned:", 30)
# Seven days form a full week.
print("Full weeks:", 30 // 7, "Extra days:", 30 % 7)
Statement What Python evaluates Displayed line
First print One string Python challenge
Second print A label and the integer 30 Days planned: 30
Third print 30 // 7 is 4; 30 % 7 is 2 Full weeks: 4 Extra days: 2

The comment produces no output. There are four source lines containing instructions or explanation, but only three calls that display a line. Counting source lines is not a reliable way to predict output length.

Guided practice

  1. Predict: write the outputs of print("30"), print(30), and print(10 + 20) on paper. The first two look alike, although their arguments are different types. That distinction becomes visible on Day 2.
  2. Modify: change the plan to 31 days. Work out the week count and remainder by hand before rerunning. Expect four full weeks and three extra days; a program that still shows two has not incorporated your change consistently.
  3. Reconstruct: close the example and write a new script that prints a course title, a daily practice target, and the target for three days. Use one arithmetic expression rather than typing the already-calculated total. Explain why the arithmetic expression makes a later target change easier to maintain.

Keep a short evidence note: your prediction, observed output, and any difference. A difference is a debugging clue, not a reason to abandon the lesson. Changing several lines at once makes it harder to determine which change repaired a problem.

Daily challenge

Build a study commitment card as a five-line Python output. The fictional learner is Alex, the course is Python, the plan lasts 30 days, and the daily target is 90 minutes. Calculate the total planned minutes inside the program. You may use only print, literal values, arithmetic, and comments today.

Requirement Acceptance evidence
Learner line Learner: Alex
Course line Course: Python
Plan line Planned days: 30
Daily line Daily minutes: 90
Calculated total Total planned minutes: 2700

Then change the daily target to 60. The final total must become 1800. This second case checks whether your output follows the actual inputs rather than a manually typed answer. It does not require variables yet; tomorrow you will improve that duplication.

Reference solution

Compare after attempting the challenge
print("Learner:", "Alex")
print("Course:", "Python")
print("Planned days:", 30)
print("Daily minutes:", 90)
print("Total planned minutes:", 30 * 90)

This version meets the original five-line contract. It repeats the daily target in two places, which is a maintenance weakness rather than a syntax error. Day 2 introduces one named value that both the daily line and total calculation can reuse.

Debug and explain

Symptom Investigate First repair to try
SyntaxError near a string Matching quotation marks and parentheses Close the string or call correctly
NameError for a word such as Alex Whether the intended text was quoted Use a string literal
Nothing appears from an arithmetic expression in a script Whether the result is displayed Wrap the expression in print
Old output appears after editing Which file or cell you ran Save and rerun the intended source

Read an error from its final line upward: identify the error type, then the reported source line. A parser can notice a mistake after the place that caused it, so inspect the preceding line too. Never “repair” an error by deleting a required output without checking the challenge contract.

Explain aloud: why does quoted arithmetic stay text? Which line creates the total, and which part displays it? Why might a notebook show an expression that a script does not? If you can answer only while looking at the code, try the reconstruction exercise again.

Review and next step

Save your card and its two checked outputs. Tomorrow, recall the five required lines before opening this page. Move on when you can run the script from the intended environment, explain the arithmetic, and repair an unmatched quote. Day 2 will give the repeated values meaningful names.

Sources and verification

Original teaching examples checked with Python 3.12.14. Library behavior reviewed against these primary references on October 3, 2026. Day 26's examples also use Beautiful Soup 4.14.3.

DAILY CHECKPOINT

Check your understanding

Five questions, 20 points each. Pass at 85% or above, which requires all five correct. Feedback explains each answer; revise the lesson and retry when needed.

01. What does a comment beginning with # do?

02. Which order do ordinary consecutive statements execute in?

03. What should you inspect first after a traceback?

04. What does print(2 + 3) display?

05. How do you check a changed program responsibly?

Review your practical work

Check these statements after running your own challenge. This is your self-review; the website does not execute or assess your Python code.

Pass the knowledge check and finish the practical self-review to save completion.