A. Programming Concepts and Skills · Programming Basics: Data, Decisions and LoopsYour First Python Programs: Output, Sequence and Comments
A2.1 A2.2 A4.2About 65 minutes
Learning goals- I can write, save and run a Python 3 program.
- I can use
print to display text and numbers, including with sep and end. - I can explain that a program runs in sequence, one statement at a time from top to bottom.
- I can write useful comments, including a header comment.
- I can describe the input, process, output model.
Words to know
program
A set of instructions, written in a programming language, that a computer carries out.
Python 3
The programming language used in this course. It is free, widely used and easy to read.
statement
One complete instruction, usually one line of code, such as print("Hi").
sequence
The basic control structure: statements run one after another, in the order they are written.
string
A piece of text in quotation marks, such as "Hello".
function call
Using a named, ready-made instruction, written as its name followed by parentheses, such as print(...).
comment
A note for humans that starts with #. Python ignores everything from # to the end of the line.
IDE
Integrated development environment: an app with an editor to type code, a button to run it and tools to find errors (for example IDLE or Thonny).
Talking to a very literal helper
It is a snowy January morning. Your phone buzzes: "Buses cancelled today." Somebody wrote a program that checked the weather report and sent that message. A program is just a list of instructions. The computer follows them exactly, one at a time, in order. It never guesses what you meant.
That is the big idea of this whole course. Computers are fast and never get bored, but they are completely literal. Your job as a programmer is to give instructions that are precise enough for something that cannot think for itself.
In this course you will write every program in Python 3.
Remember from Grade 9
In Grade 9 math (MTH1W) you read, predicted and changed short Python programs that used variables, print, for and while loops and def functions. If you did that, parts of this unit will feel familiar. If you did not, that is fine: this unit assumes no programming experience and starts from the very beginning.
Getting Python
You need one of these (all free):
- Python 3 from python.org. It comes with IDLE, a simple IDE. In IDLE choose File → New File, type your program, save it with a name ending in
.py (for example hello.py), then choose Run → Run Module (or press F5). - Thonny, a beginner-friendly IDE that installs Python for you.
- An online Python 3 editor in a web browser, if you cannot install software. Make sure it says Python 3.
An IDE usually has two windows. The editor is where you type and save a whole program. The shell (it shows >>>) runs one line at a time and shows output. Use the shell for quick experiments and the editor for real programs.
The print function
print displays something on the screen. You write the word print, then parentheses, and inside them what you want to show.
- Text must be inside quotation marks:
print("Hello, Ontario!"). Single quotes work too: print('Hello'). The text in quotes is called a string. - Numbers do not need quotes:
print(42) shows 42, and print(3 + 4) shows 7, because Python works out the sum first. - You can print several things at once by separating them with commas. Python puts one space between them:
print("Score:", 10) shows Score: 10. print() with nothing inside prints an empty line.
Two optional settings change the spacing:
sep is what goes between items (normally a space).end is what goes at the end (normally a new line, so the next print starts on a new line).
print("Hello, Ontario!")
print("Score:", 10)
print(3 + 4)
print()
print("2026", "10", "16", sep="-")
print("Loading", end="...")
print("done")
Try this in your editor. When a caption shows output line by line, the | marks where one line ends and the next begins. Output, line by line: Hello, Ontario! | Score: 10 | 7 | (blank line) | 2026-10-16 | Loading...done
Sequence: one statement at a time
A program runs in sequence. Python starts at line 1, finishes it, then moves to line 2, and so on to the end. If you change the order of the lines, you change what the program does.
Sequence is the first of three control structures you will use in every program. The other two are selection (choosing between options, Lessons 9 and 10) and repetition (loops, Lessons 11 to 13).
Python reads your file from line 1 down. The comment on line 1 is skipped, and each print puts one line on the screen, in the same order as the code.Comments
A comment begins with #. Python ignores it. Comments are for people: you next month, your teacher, or a teammate.
Professional programmers follow some habits that you should start now:
- Begin every program with a header comment: the file name, your name, the date and what the program does.
- Add a comment before each section of code to explain what it is for or why it is done that way.
- Do not comment the obvious.
# print hello above print("hello") adds nothing.
You can also put a comment at the end of a line: print(25 * 4) # 25 cents times 4 quarters.
# File: snow_day.py
# Author: Sam Tremblay
# Date: 2026-10-16
# Purpose: Displays a school closure notice.
# Heading
print("=====================")
print(" SCHOOL BUS NOTICE")
print("=====================")
# Details for families
print("All buses are cancelled today.")
print("Schools remain open.")
A short program with a header comment and section comments. Spaces inside the quotes are printed exactly as typed. Output, line by line: ===================== | SCHOOL BUS NOTICE | ===================== | All buses are cancelled today. | Schools remain open.
Special characters in strings
Inside a string, a backslash starts an escape sequence:
\n starts a new line: print("Line one\nLine two") prints two lines.\t inserts a tab.\" puts a double quote inside a double-quoted string. You can also just use the other kind of quote: print('She said "Go Leafs!"').
Worked exampleExample 1: Predict the output
Predict exactly what this program prints. Then explain why.
print("A", "B", "C")print("A", "B", "C", sep="")print("Red", end=" ")print("Maple")# print("Leaf")
- Line 1: three items with the default
sep, which is one space: A B C. - Line 2:
sep="" means nothing goes between the items: ABC. - Line 3:
end=" " replaces the usual new line with a space, so the next output continues on the same line. - Line 4 prints
Maple after that space, then a normal new line. Together lines 3 and 4 show Red Maple. - Line 5 starts with
#, so it is a comment. Nothing is printed.
Three lines: A B C, then ABC, then Red Maple.
Worked exampleExample 2: Writing a program to a specification
Write a program that prints a three-line label for a jar of maple syrup: the product name, the volume 500 mL, and the line Made in Ontario. Include a header comment.
- Plan the output first, line by line. You need three
print statements, in this order. - Write the header comment with file name, author, date and purpose.
- Type the program:
-
# File: syrup_label.py
- # Author: (your name)
- # Date: 2026-10-16
- # Purpose: Prints a label for a jar of maple syrup.
- print("Pure Maple Syrup")
- print("500 mL")
- print("Made in Ontario") - Run it and compare the output with the specification, line by line.
The program prints Pure Maple Syrup, 500 mL and Made in Ontario on three lines.
Almost every program follows the input → process → output model. This lesson is mostly about output; you will add input in Lesson 7.Just for funPython is not named after the snake. Its creator, Guido van Rossum, named it after the British comedy show Monty Python's Flying Circus. That is why so many Python examples online use the words "spam" and "eggs".
Hands-on activitySet up and make a poster
You need: a computer, tablet or Chromebook with Python 3 (IDLE, Thonny or an online editor).
- Open your IDE. In the shell (the
>>> window), type print("Hello") and press Enter. Then type print(12 * 12). - Open a new file in the editor. Write a program with a header comment that prints a small poster for a winter carnival, a hockey game or a bake sale. Use at least 5
print statements, one empty print(), and one sep or end. - Save it as
poster.py and run it. - Now swap two of the
print lines and run it again. What changed? - Delete one closing parenthesis
) and run it. Read the error message Python shows, then fix it. (You will learn to read error messages properly in Lesson 14.)
What to look for: the poster prints in exactly the order of the code; swapping two lines swaps those two lines of output; the missing ) gives a SyntaxError such as '(' was never closed, and the program does not run at all until it is fixed.
Your turn
1What does this print?
print("Go", "team", "go!")
Go team go! (the default separator is one space).
2What does this print?
print("10", "20", "30", sep=", ")
3What does this print? How many lines of output are there?
print("Top")print()print("Bottom")
Three lines: Top, an empty line, then Bottom.
4What does this print?
print("snow", end="")print("ball")
snowball. With end="" nothing is added after snow, so ball continues on the same line.
5Explain the difference between print(5 + 3) and print("5 + 3").
print(5 + 3) calculates the sum and shows 8. print("5 + 3") shows the string exactly as typed: 5 + 3. Quotes mean "show this text".
6Write a program that prints your name on one line and your favourite Canadian city on the next line. Include a header comment.
Sample:
# File: about_me.py# Author: Mia Chen# Date: 2026-10-16# Purpose: Prints my name and favourite city.print("Mia Chen")print("Halifax")
Any two print statements in that order, with a header comment, are correct.
7Your friend's program has a comment # add 1 to x above the line x = x + 1. Is this a useful comment? Explain.
Not very. It only repeats what the code already says. A useful comment explains why, for example # count one more snow day.
More practice: warm-up
1What symbol starts a comment in Python?
2Which control structure runs statements one after another from top to bottom?
3What does print(7 * 6) display?
4What does print("Hi" , "there") display?
5What file extension do Python programs use?
More practice: on your own
1What does this print?
print("a", "b", sep="")print("c", end="!")print("d")
ab, then c!d. The sep="" joins a and b; the end="!" puts ! after c instead of a new line, so d follows on the same line.
2Write one print statement that shows 2026/10/16, using three separate items.
print(2026, 10, 16, sep="/"). The numbers are printed with / between them.
3Put these lines in the right order so the program prints a countdown 3, 2, 1, Liftoff!:
print("Liftoff!")print(2)print(3)print(1)
print(3), print(2), print(1), print("Liftoff!"). In a sequence, the order of the code is the order of the output.
4Write one print statement that uses \n to print Line 1 and Line 2 on separate lines.
print("Line 1\nLine 2"). The \n starts a new line inside the string.
5What is the difference between the editor and the shell in an IDE?
The editor is for writing and saving a whole program in a .py file and running it all at once. The shell (>>>) runs one line as soon as you press Enter; it is good for quick tests, but the code is not saved as a program.
Challenge
1Using exactly one print statement, display this two-line output:
print("Name: Jo\nGrade: 11"). The escape sequence \n breaks the line. (print("Name: Jo", "Grade: 11", sep="\n") also works: the separator becomes a new line.)
2Predict the output exactly, including spaces:
print("x", "y", sep="--", end="|")print("z", end="|")print()
x--y|z| on one line. The first print joins x and y with -- and ends with |. The second prints z|. The final print() just ends the line.
3A program has 6 statements. Statement 4 has a missing closing quote. Statement 2 prints Hello. When you press Run, is Hello displayed before the error? Explain.
No. A missing quote is a syntax error. Python checks the whole file for syntax errors before it runs anything, so no statement runs and Hello never appears. (Errors that happen while the program runs, such as dividing by zero, are different: lines before them do run. See Lesson 14.)
Check your understandingQuiz
1. What does print("3", "4", sep="") display?
3. In what order does Python run the statements of a simple program?
4. What does print("Hi", end="") followed by print("!") display?
5. Which is the most useful comment?
6. In the input, process, output model, displaying a result on the screen is:
For parents and teachersBig idea: this lesson starts expectations A2.1 (input, processing and output) and A2.2 (sequence), and the professional conventions in A4.2 (header comments and helpful comments).
How to help: make sure your teen can install or open Python 3 (python.org with IDLE, Thonny, or an online Python 3 editor). Ask them to show you their poster program and explain one line. You do not need to know Python: asking "what does that line do?" is very helpful.
Common difficulties:
- Forgetting quotation marks around text, or mixing quote types (
"Hello'). - Typing
Print with a capital P. Python is case-sensitive. - Expecting
print("5 + 3") to show 8. - Writing code in the shell and losing it. Real programs belong in a saved
.py file. - Smart quotes: if code is typed in a word processor, the curly quotes “ ” break Python. Type code in the IDE.