Skip to content
KALANBLON
Show contents

Chapter 1 of 3 · 15 min

Your very first program

By the end of this chapter, you'll be able to

  • Run a Python program in your browser
  • Display text with print()
  • Make the computer calculate and display the result
  • Recognise and fix a simple SyntaxError

A program is a list of instructions

Imagine leaving a note for a very obedient but very literal friend: they'll do exactly what is written, in order, without guessing what you meant. That's a computer.

A program is a sequence of instructions written in a programming language, a language with a very strict vocabulary and grammar that the computer knows how to interpret. Python is one of these languages: it's readable, widely used (web, data, AI, automation) and perfect for beginners.

When you run a Python program, a piece of software called the interpreter reads your lines from top to bottom, one by one, and carries out each one before moving on to the next.

No more lines to read: the program has finished.

Step 5 of 5
Text description of the animation
  1. The program has three lines. The interpreter will read them from top to bottom.
  2. Line 1: print displays the text between quotes in the console.
  3. Line 2: Python first computes 7 * 6, then displays the result, 42.
  4. Line 3: one last message is displayed.
  5. No more lines to read: the program has finished.

Your first instruction: print()

print() is a function: a ready-made tool that does one specific job. This one displays whatever you give it between the parentheses.

# Everything after a # is a comment: Python ignores it.
print("Hello, Kalanblon!")      # Text: between quotes
print(7 * 6)                     # A calculation: Python works it out first
print("7 x 6 =", 7 * 6)          # Several values, separated by commas

This program displays:

Hello, Kalanblon!
42
7 x 6 = 42

The text between quotes is called a string. The quotes tell Python: "this is text, don't try to understand it". Without quotes, Python tries to interpret what you wrote as code.

Your turn

Mini-lab: introduce yourselfPython 3.13

Output

Click “Run”: Python will load in your browser (about 10 MB the first time).

Your code runs in your browser, isolated from the page. · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor

Worked exercise

Worked exercise: the receipt

Mariana buys 3 notebooks at 2 reais each and 1 pen at 4 reais. Write a program that displays the total to pay, in the form Total: 10 reais.

Hint 1
You can put a calculation straight into print(), without quotes around it.
Hint 2
The total is 3 * 2 + 4. Python follows the order of operations, just like in maths.
Show the solution and common mistakes
print("Total:", 3 * 2 + 4, "reais")

Common mistakes:

  • Writing print("Total: 3 * 2 + 4"): everything is between quotes, so Python displays the calculation as it is instead of working it out.
  • Writing print(Total: 3 * 2 + 4): without quotes around the text, Python raises a SyntaxError.

Summary

  1. 1A program is a sequence of instructions run from top to bottom.
  2. 2print() displays text or the result of a calculation.
  3. 3Text is written between quotes: it's a string.
  4. 4An error message tells you the line and the kind of problem: read it, it's there to help.

Your progress is saved on this device. Create a free account to keep your progress on all your devices.