Browser lab12 min+60 XP

Meet Python

Why Python reads almost like English, and how to use it as a super calculator.

0% done

Code runs right here in your browser. Nothing to install.

TASK 1

Learn it

Key idea

The Python interpreter reads your code one line at a time and runs it.

Key words
hello.pyyour codePythonreads one lineat a time0110 1001machine codeCPUruns itHello!output
Your code is turned into machine code that the CPU can run.

Deep down, computers only understand machine code: long patterns of 1s and 0s. Writing that by hand is painful, so people invented high-level languages like Python that look more like English. A program called the Python interpreter reads your code one line at a time, from top to bottom, and carries out each instruction.

Python was created by Guido van Rossum and released in 1991. It is popular because it is easy to read and has ready-made tools for almost everything: games, websites, robots, data science and artificial intelligence.

Python is also a brilliant calculator. print(2 + 3) prints 5 because Python works out the sum first. But print("2 + 3") prints the text 2 + 3, because anything inside quote marks is treated as text, not maths.

Real life linkPython is named after the comedy group Monty Python, not the snake.
Example code
print(2 + 3)
print("2 + 3")
print(60 * 60)
print("Hours in a week:", 24 * 7)
TASK 2

Try it yourself

+10 XP

Make Python work out how many hours are in a year (365 days, 24 hours each). Print the answer using a calculation, not by typing the number.

Create a free account to start this lab

Sign in to write, run and check your code here. Your progress, XP and code are saved to your account. No card needed.

TASK 3

Capture the flag

+10 XP

What does print("5 + 5") show in the terminal?

Create a free account to start this lab

Sign in to answer the flag question. Your progress, XP and code are saved to your account. No card needed.

HOMEWORK

Time calculator

+20 XP

Print two results using calculations: the number of seconds in a day and the number of minutes in a week. Add a label to each line, like Seconds in a day: 86400.

Create a free account to start this lab

Sign in to do this homework and have it checked. Your progress, XP and code are saved to your account. No card needed.