← Complete program

Chapter 3 · Course 3 c03-m03

What happens when you press Run?

Your goal Predict a small program's output and compare it with what you observe, without treating the message as proof about the real world.

The lesson, the vocabulary, the worked example and the mission are separate blocks. You can follow them in order or return to the one you need.

Video explanation

This English explanation has English subtitles. Its examples may use a separate practice dataset; use the data stated in the written mission for your answers.

01

Story · optional context

The story so far

You are the new data team member at Aster Motors. Mara Sol is preparing messages about Noctis 01, a prototype car. Two schedules disagree. Before asking a program to display either one, she wants you to understand exactly what Run produces and how to check the displayed text.

You can open this page directly. print('Hello') is a Python instruction that displays Hello. You can reason through every task on paper if execution is not available to you.

02

Before the lesson

Purpose of this course

Predict a small program's output and compare it with what you observe, without treating the message as proof about the real world.

Topics covered

Explain what Python does when a program starts.; Follow two instructions from top to bottom and predict output.; Separate written code, expected output, and observed output.; Find the first line explaining a difference.

What you will learn

  • Explain what Python does when a program starts.
  • Follow two instructions from top to bottom and predict output.
  • Separate written code, expected output, and observed output.
  • Find the first line explaining a difference.

PART 1 · THE LESSON

Understand step by step

1

Lesson · explanation

Writing code does not run it yet

When Noor writes print('Hello'), she prepares an instruction. The word does not appear on the output screen by magic as she types. She must ask the program to work, often with a Run button. That button starts Python reading the code available at that moment.

Think of a play. Its script can be written and put in a folder, but the actors do not perform until the show starts. Code is like the script, running is like the performance, and displayed text is part of what the audience sees. This picture separates preparing, starting, and observing.

Python is software that understands instructions written in its language. In these first examples, it starts with the first line and then moves to the next. If an instruction cannot be understood, it may stop and show an error. Today we follow mainly simple print instructions that display messages.

A run does not check the real world. If the code says print('Car ready'), Python can display those words without seeing the car. Run confirms that an instruction could be followed; it does not confirm that the sentence is true about Noctis 01.

Pause and think

Noor types print('Hello') and closes the file without running it. Has she observed program output?

See the explanation

No. The code was written, but no run produced the output Hello.

2

Lesson · explanation

Read print as a request to display text

The instruction print('Start') asks Python to display Start. The word print names a Python function. Parentheses surround what we give it, and the quotes mark the text to display. You do not need to know every function to understand this first one: it puts a message in the output area.

On the screen you normally see Start, without the word print, its parentheses, or its quotes. Compare code with a request to a friend: say the word Start. Your friend says Start, not the entire request. If you copy the code's punctuation into your predicted output, you have confused the instruction with its effect.

With two lines, print('Start') followed by print('End'), Python shows Start and then End, each on its own line. Swap the two instructions and their order on the screen changes. The words inside the quotes stay the same; only their positions in the code move. That will matter in the mission.

Characters inside the quotes matter. print('Test tomorrow') and print('Test Monday') announce different days. Even one letter or space can change the visible message. When checking output, read each line exactly as written rather than replacing it with what you think Mara intended.

Pause and think

After print('Noctis 01'), do we see the whole code or just the name?

See the explanation

We see Noctis 01. The word print, parentheses, and quotes are part of the instruction, not of the displayed text.

3

Lesson · explanation

Predict output before clicking Run

Expected output is what you predict before running. Take a sheet of paper and write one output line for each print instruction. You do not need a computer to make this prediction. It forces you to read the code from top to bottom and gives you something to compare with the actual screen.

In the worked example, the first line displays Noctis 01. The second displays Check planned tomorrow. The expected output is those two lines in that order. It does not say the check took place: planned describes a future intention. Your prediction concerns the screen, not the condition of the car.

Imagine planning a walk to the bakery and then the library. If you reach the library first, you know the observed order differs from your plan. Without a plan, you might see both places without noticing the swap. Expected output plays the role of that plan.

In the mission, the current code displays Meeting at 9 first and Check the cards second. Write those messages in that order before looking at the screenshot. Do not start with Mara's desired order, because it is not yet the order of the code. Keeping current and wanted separate prevents you from assuming Python can read your intentions.

Pause and think

Which mission message appears first with the current code?

See the explanation

Meeting at 9 appears first because its print instruction is on the first line.

4

Lesson · explanation

Observe and compare line by line

Observed output is what the result area actually shows after Run. Compare it with your prediction: first line with first line, second with second. If both match, this small program behaved as expected in this run. If nothing appears, first check that the run really started.

A difference may come from swapped lines, a changed letter, or an older code version. Do not change the entire program at random. Find the first line where expected and observed output stop matching. In a puzzle, you look for the first misplaced piece instead of throwing away the whole picture. The same habit helps with code.

Suppose you expect Check the cards then Meeting at 9, but the screenshot shows the opposite order. The first difference appears on line one. The current code prints the meeting first. Python did not invent new words; it followed the written order. To meet Mara's request, change that order.

A successful comparison answers whether the program displayed what was expected. It does not answer whether anyone really checked the cards. For that second question, inspect the records and ask the responsible people. Keep the two checks separate in your report.

Pause and think

The screenshot contains both right messages but in the wrong order. Where do you look first for the cause?

See the explanation

Look at the order of the two print instructions. The first output normally follows the first instruction.

5

Lesson · explanation

Change the smallest thing that explains the difference

Once you find the cause, change only what is necessary. In the mission, the words of both messages are correct; their order is wrong. Swap the two code lines. The instruction displaying Check the cards moves first, and the one displaying Meeting at 9 moves second.

You can test that change on paper before clicking. Read the new line one: it displays Check the cards. Read the new line two: it displays Meeting at 9. That is the new expected output. If the workspace is available, run the changed code and compare the screen to those two lines.

Avoiding unnecessary changes makes the result easier to explain. If you also change the wording, punctuation, and file name, you cannot tell which change fixed the order. One small change followed by another run provides clearer evidence. This habit will help when you face harder bugs later.

Check that the version being run is the one you just changed. A screen may still show an old result if nobody has rerun the program. Correct order in written code is not yet observed output. Run, observe, and compare again.

Pause and think

What is the smallest code change that shows the warning before the meeting time?

See the explanation

Swap the two print lines, run the changed code, and check that Check the cards appears first.

6

Lesson · explanation

A displayed message does not prove it is true

A program can display exactly the requested sentence and still say something false about the world. print('Check complete') works even if no mechanic signed a record. Python checks whether it can follow the instruction; it does not leave the office to inspect Noctis 01. Remember this basic limit.

Imagine a sign on a door saying cake ready. The fact that a printer made the sign does not prove that the cake is baked. Someone must check the oven. In the same way, Check the cards says what the screen shows. It proves neither that the cards were read nor that their contents are correct.

After fixing the mission, you can say the program now displays the warning first. The new observed output supports that statement. You cannot say all cards have been checked on that basis alone. To make that claim, you would need a real inspection and a source that records it.

This difference between program behavior and data truth will appear throughout the course. You will learn to write code, check its inputs, and explain its limits. A careful data engineer can answer both what did the program do and what do we actually know about the parts.

Pause and think

After swapping the lines, Mara sees Check the cards first. Can she announce that all cards were checked?

See the explanation

No. The screen shows the order of the message, not whether anyone performed the real check.

PART 2 · WATCH IT WORK

A complete worked example

Follow each step, then the result

Worked example: two lines, two outputs

Mara writes line 1 print('Noctis 01') and line 2 print('Check planned tomorrow'). What appears after Run?

  1. Before running, read line 1: print will show Noctis 01.
  2. Read line 2: it will show Check planned tomorrow after the first line.
  3. Write expected output on two lines: Noctis 01, then Check planned tomorrow.
  4. Run if the workspace is available, then compare each displayed line. A match means this small program behaved as expected.
  5. Do not turn “check planned” into “check completed” in a report. The text only describes a plan.
What this shows

Predicting, observing, and comparing shows what the program did while keeping real car facts separate.

How this helps with your mission

The example showed how to predict two print outputs, observe them, and keep planned separate from completed. In the mission, use the same method to record the current order, predict Mara's desired order, swap the two instructions, and check the new output. This helps Mara correct the public message while reminding her that the screen does not prove the cards' real status.

PART 3 · YOUR TURN

Use the lesson to solve the mission

Story scene · practical task

Mission: put the announcement in order

Noor must show a short message on the Noctis 01 team screen. The code says, in order: line 1 print('Meeting at 9'); line 2 print('Check the cards'). Mara wanted “Check the cards” first. A screenshot shows the current order. The story gives you a few minutes before the public display, but there is no time limit on your learning.

Your task

  1. Write the current output line by line, without copying print.
  2. Write the output order Mara wants.
  3. Say the smallest code change and predict the new output.
  4. Explain what the new output proves about the program and what it cannot prove about the cards.

How to know you have succeeded

  • You give “Meeting at 9” and then “Check the cards” for current code.
  • You put “Check the cards” first in desired output.
  • You swap the two code lines and predict the new order without changing messages.
  • You say the display was corrected but the cards still need a real check.
Open this mission in the browser workspace

Try code or SQL and keep a local draft. The mission questions are checked separately below.

Check the facts in your mission

Answer each factual question, then write your report in your own words. The program checks the choices; compare the report with the worked answer below.

1. What output does the current code produce, in order?
2. What order does Mara want?
3. What minimal change should be made and checked?
4. What does the new output prove if the warning appears first?
See the worked answer
  1. Current output: first Meeting at 9, then Check the cards.
  2. Wanted output: Check the cards, then Meeting at 9.
  3. Swap instructions: print('Check the cards') before print('Meeting at 9'). Output follows that order after running.
  4. The match proves the program displays the wanted order. It does not prove anyone finished checking the cards.

You can compare expected and observed output. Next, you will read error messages and correct the first cause rather than guess.

Before you leave

Remember this

  • Writing code does not run it; Run starts Python on the available instructions.
  • print('text') displays the text without the function name, parentheses, or quotes.
  • Predict output and compare it line by line with observed output to find differences.
  • To reverse two messages, swap their instructions and run the program again.
  • Correct output shows code behavior; it does not prove a real event took place.
A–Z

Part of the lesson · keep nearby

New words, explained

These are the names of ideas used in the lesson above. Return here whenever a word feels unfamiliar.

Execution
The time when Python reads and follows program instructions.
Instruction
A requested action, such as showing text with print.
Order
Instruction positions: here Python reads the first line and then the second.
Expected output
What you predict before running.
Observed output
What the workspace actually shows after running.
Comparison
Checking expected and observed lines one by one.