Skip to content
aviral gupta

// B1.1 · ~25 min · Beginner

Install Python and run your first script

After this lesson Python 3.14 runs on your computer. You can check its version, try code at the >>> prompt, and write a .py file that prints text and numbers.

Lesson 1 of 5 in B1 First steps

Start of the module

You will be able to

  • Install Python 3.14 and check which version runs with python --version
  • Tell the interactive prompt (>>> and ...) from a script, and run a script with python hello.py
  • Use print() to show text and numbers, with several items on one line
  1. Warm-up · Activity 1 of 7

    Before you install anything: what do you expect a Python program to be?

  2. Predict · Activity 2 of 7

    Predict before you read on: what does this line print?

    print("I am", 30 + 5, "years old")
  3. Practice · Activity 3 of 7

    Match each thing you type or see to what it means.

  4. Practice · Activity 4 of 7

    Fill in one character so that the line prints Hello Ada, with a space between the words.

    print("Hello"____ "Ada")
    print("Hello" "Ada")
  5. Practice · Activity 5 of 7

    This file is run as a script with python main.py. What does it print?

    2 * 10
    print(2 + 3)
  6. Brain teaser · Activity 6 of 7

    Brain teaser. What does this print?

    print("2 + 2", 2 + 2)
  7. Apply · Activity 7 of 7

    Mini-task, on your own computer. Create a file hello.py in a folder of your choice, with three print() lines: your name, the Python version you installed, and I ran my first script. Open a terminal in that folder and run python hello.py (python3 hello.py on macOS and Linux).

    Check your work against this list

Build it yourself

Read the worked example, then write the exercises. Your code runs in your browser or on your computer and is never uploaded.

Worked example

A first script

This is a whole Python program. Save it as main.py in a new folder, open a terminal there and run python main.py (python3 main.py on macOS and Linux). Python runs the lines from top to bottom and prints the output below. Then change a text or a number, save, and run it again.

main.py

# main.py: a first script. Run it with: python main.py
print("Hello, world!")
print("Python runs this file from top to bottom.")
print()
print("2 + 3 =", 2 + 3)
print("Minutes in a day:", 24 * 60)

Run it with

python main.py

Output

Hello, world!
Python runs this file from top to bottom.

2 + 3 = 5
Minutes in a day: 1440
  • The first line starts with #: it is a comment, and Python ignores it.
  • print() with nothing inside writes the empty line in the middle of the output.
  • "2 + 3 =" is printed as written, while 2 + 3 without quotes becomes 5.
  • Each print() call writes one line, and the items inside it are separated by a space.

Exercises

Exercise 1 of 2

Hello from a file

On your computer, save the starter as main.py and run python main.py (python3 main.py on macOS and Linux). It prints one line. Add a second print() so the script prints exactly these two lines: Hello, Python! This is my first script. You can also run the checks on this page.

This exercise needs Python on your computer (the browser version cannot run it). The files and commands are below.

Hints
  1. Hint 1

    Each print() call writes one line, so a second line needs a second print().

  2. Hint 2

    Put the text in quotes and copy it exactly, including the full stop.

  3. Hint 3

    print("This is my first script.")

Show a solution

One way to solve it. Yours can look different and still pass the checks.

print("Hello, Python!")
print("This is my first script.")
Run it on your computer

Install Python 3.14 or newer. Save these files in one folder, open a terminal in that folder, and run the commands below.

main.py

print("Hello, Python!")
# Add a second line: This is my first script.

test_main.py

from learnrun import run_main


def lines():
    return run_main().splitlines()


def test_first_line():
    """The first line is Hello, Python!"""
    got = lines()
    assert got[:1] == ["Hello, Python!"], f"the first line is {got[:1]!r}, expected ['Hello, Python!']"


def test_second_line():
    """The second line is This is my first script."""
    got = lines()
    assert got[1:2] == ["This is my first script."], f"the second line is {got[1:2]!r}, expected ['This is my first script.']"


def test_two_lines():
    """Exactly two lines are printed"""
    got = lines()
    assert len(got) == 2, f"the script printed {len(got)} line(s), expected 2"

On macOS and Linux, type python3 wherever these commands say python, as in the first lesson.

Run the program:

python main.py

Run the checks (needs learnrun.py in the same folder):

python learnrun.py test
Download learnrun.py

Exercise 2 of 2

A name card

Write a script that prints this card, one print() per line: Name: Ada Lovelace Born: 1815 (an empty line) Age in 1843: 28 Let Python work out the 28 with 1843 - 1815 instead of typing it. Run it on your computer with python main.py (python3 main.py on macOS and Linux).

This exercise needs Python on your computer (the browser version cannot run it). The files and commands are below.

Hints
  1. Hint 1

    print("Born:", 1815) prints Born: 1815, because print() puts a space between its items.

  2. Hint 2

    print() with nothing between the parentheses writes an empty line.

  3. Hint 3

    print("Age in 1843:", 1843 - 1815): the sum has no quotes, so Python works it out.

Show a solution

One way to solve it. Yours can look different and still pass the checks.

print("Name: Ada Lovelace")
print("Born:", 1815)
print()
print("Age in 1843:", 1843 - 1815)
Run it on your computer

Install Python 3.14 or newer. Save these files in one folder, open a terminal in that folder, and run the commands below.

main.py

print("Name: Ada Lovelace")
# Next: Born: 1815, an empty line,
# then Age in 1843: followed by 1843 - 1815.

test_main.py

from learnrun import run_main


def lines():
    return run_main().splitlines()


def test_name_and_year():
    """The card starts with the name and the year of birth"""
    got = lines()[:2]
    assert got == ["Name: Ada Lovelace", "Born: 1815"], f"the first two lines are {got!r}"


def test_empty_line():
    """The third line is empty"""
    got = lines()[2:3]
    assert got == [""], f"the third line is {got!r}, expected an empty line"


def test_age():
    """The last line is Age in 1843: 28"""
    got = lines()[3:]
    assert got == ["Age in 1843: 28"], f"the lines after the empty one are {got!r}, expected ['Age in 1843: 28']"


def test_calculated():
    """The age is calculated, not typed"""
    with open("main.py", encoding="utf-8") as f:
        code = f.read()
    assert "1843 - 1815" in code, "calculate the age with 1843 - 1815"

On macOS and Linux, type python3 wherever these commands say python, as in the first lesson.

Run the program:

python main.py

Run the checks (needs learnrun.py in the same folder):

python learnrun.py test
Download learnrun.py

Common mistakes

Typing a terminal command at the >>> prompt

python hello.py

What Python prints

SyntaxError: invalid syntax

Why, and the fix

python hello.py is a command for the terminal, not Python code. At the >>> prompt, Python tries to read it as code and fails. Leave the interpreter with exit(), then type the command at the normal terminal prompt, in the folder where hello.py is saved.

A capital P in print

Print("Hello")

What Python prints

NameError: name 'Print' is not defined. Did you mean: 'print'?

Why, and the fix

Python tells upper and lower case apart, so Print and print are different names, and only print exists. Write print in lower case. The message even suggests the right name.

A missing closing parenthesis

print("Hello"

What Python prints

SyntaxError: '(' was never closed

Why, and the fix

Every ( needs a matching ). Python reads to the end of the file looking for it and then gives up before running anything. Add the ) at the end: print("Hello").

Python in the browser: Pyodide 314.0.7, MPL-2.0. Licence and source

Exit ticket

5 questions, no hints. Score 80% or more to complete the lesson.

Finish every activity above to unlock the exit ticket.

Report a problem

Spotted something wrong or unclear? Say what, and it will be checked and fixed.

#

At least 20 characters.

Only if you want a reply.

Key ideas

Install Python and check the version

Windows: install the Python Install Manager from python.org/downloads or the Microsoft Store; afterwards python works in any terminal. macOS: download the .pkg installer from python.org and double-click it; then use python3 in Terminal, because the python3 that ships with the Mac is usually older. Linux: Python is usually preinstalled; if python3 --version shows an older version, install a newer package. Then open a terminal and run python --version (python3 --version on macOS and Linux). It should print Python 3.14 and a last number, such as Python 3.14.7.

The interactive prompt

Type python on its own and you get the interactive interpreter, often called the REPL. It shows >>> when it waits for a new statement, and ... when a statement goes on over several lines. Type an expression such as 7 * 6, press Enter, and the value appears on the next line. It is the quickest way to try something. Nothing you type there is saved. Leave it with exit().

Scripts and print()

A script is a plain text file ending in .py. python hello.py runs it from the first line to the last. In a script, a bare expression such as 7 * 6 is worked out but not shown: to see a value, pass it to print(). print() takes any number of items, separated by commas, and writes them on one line with a space between them. Text in quotes is printed as written, without the quotes; code without quotes is worked out first. print() with nothing inside writes an empty line.

Sources

Last reviewed September 29, 2026