
Before you can take a disc image apart, you need something to take it apart with. In this course that is Python, and this section gets it onto your computer and gets your first program running. It also introduces the terminal, the window where you type commands, because that is where you will run everything you write.
If you have used Python before, check the version (below) and skip to S3.
A computer does exactly what it is told, and a program is the list of instructions you tell it. Python is a language for writing those instructions: a way of writing them that people can read, and that a program also called Python - the interpreter - reads and carries out, one line after another.
You write a Python program in an ordinary text file whose name ends in .py. Then you ask the interpreter to run it. That is the whole cycle, and you will go round it hundreds of times in this course: write, run, look at what happened.
The terminal is a window in which you type commands instead of clicking on things. You type a command, press ENTER, and the computer prints its answer underneath. It looks old-fashioned - and it is the same idea as the Einstein's own 0: prompt, which you will meet in S3.
Terminal, press ENTER.cmd, press ENTER.A line ending in $, % or > appears, with a flashing cursor after it. That is the prompt: the terminal waiting for you.
The course needs Python 3.9 or later. First see whether you already have it.
On macOS or Linux, type this at the prompt and press ENTER:
python3 --version
On Windows, type:
python --version
If the answer is Python 3.9 or any higher number - Python 3.13.5, for instance - you have it, and can go on to Your First Program.
If the answer is an error, or a number lower than 3.9, install it:
python3.Then close the terminal, open a new one, and check the version again.
Everything in this course was written and checked on macOS, with Python 3.9 and Python 3.13. The Windows and Linux steps above follow Python's own instructions rather than our own machines, so if anything is wrong or missing for you, please tell us.
From here on, the course writes the command to run Python as python3. On Windows, type python instead wherever you see python3.
Everything you make in this course goes in one folder. Make one called edisc in your home folder, and move the terminal into it:
macOS and Linux:
mkdir ~/edisc
cd ~/edisc
Windows:
mkdir %USERPROFILE%\edisc
cd %USERPROFILE%\edisc
mkdir makes a folder ("make directory"); cd moves the terminal into it ("change directory"). The terminal is always in one folder, and when you name a file in a command, that is where it looks. Every time you open a new terminal for this course, cd into edisc first.
You need a text editor to write programs in - a plain one, not a word processor. Any of these will do:
Make a new file, type the three lines below exactly, and save it as hello.py in your edisc folder.
print("Hello from Python")
print(2 + 3)
print("The Einstein's discs have", 40, "tracks")
Run it
In the terminal, in the edisc folder:
python3 hello.py
What you should see
Hello from Python
5
The Einstein's discs have 40 tracks
Three lines, from three instructions. Here is what each one did.
print(...) shows whatever is between its brackets. print is the name of something Python already knows how to do - a function - and the brackets hold what you give it to work on.
"Hello from Python" is text: anything between double quotes is printed exactly as it is, without the quotes. Python calls a piece of text a string.
2 + 3 is not in quotes, so it is not text. It is arithmetic, and Python works it out before printing: 5.
The last line gives print three things, separated by commas: some text, a number, more text. print shows them in order with a space between each.
Python ran your lines from the top down, one at a time. Every program in this course runs that way, however long it gets.
After each change, save the file and run python3 hello.py again.
2 + 3 to "2 + 3", with the quotes. What will be printed, and why is it different?40 to 40 * 10. (* is how Python writes "times".) What does the last line say now?print(40 * 10 * 512). That is the number of bytes on an Einstein disc. Does it match the number in S1?Mistakes are normal. When Python cannot run your program it stops and tells you why - and learning to read what it says is one of the most useful things in this section. Try these two on purpose.
Leave out a bracket. Change the first line to print("Hello from Python" - with no ) at the end - and run it. The second line has not changed. You will see one of these, depending on which Python you have (the first lines show where your file is, so yours will be different):
Python 3.13:
File ".../hello.py", line 1
print("Hello from Python"
^
SyntaxError: '(' was never closed
Python 3.9:
File ".../hello.py", line 2
print(2 + 3)
^
SyntaxError: invalid syntax
Both are syntax errors: the program is not written in a way Python can read, so nothing runs - not even the lines that were fine. The newer Python points at the bracket that was never closed. The older one only notices something is wrong when it reaches the next line, and points there - so when Python points at a line that looks perfect, look at the line above it.
Put the bracket back.
Spell print with a capital P. Change the first line to Print("Hello from Python") and run it:
Traceback (most recent call last):
File ".../hello.py", line 1, in <module>
Print("Hello from Python")
NameError: name 'Print' is not defined
(Python 3.13 adds a helpful last line: Did you mean: 'print'?)
This one is different: the program was readable, so Python started running it, and stopped at the line it could not do. Python cares about capital letters: print is a function it knows; Print is a name it has never heard of. Read the last line first - it says what went wrong - and then the line number above it says where.
Put the small p back, and check the program runs again.
| Symptom | Cause |
|---|---|
zsh: command not found: pythn3 (the shell's own message; the wording varies) | The command is mistyped - or, if you typed python3 exactly, Python is not installed |
can't open file '.../helo.py': [Errno 2] No such file or directory | No file of that name in this folder: a mistyped name, or the terminal is not in edisc (cd into it), or the file was saved somewhere else |
SyntaxError | Something is mistyped - a missing bracket or quote. Check the line it names and the one above |
NameError | A name Python does not know - often a spelling or capital letter |
You have Python, a folder to work in, and the cycle you will use for the rest of the course: write a .py file, run it with python3, read what it prints. You have met print, text in quotes, and arithmetic, and you know that Python runs a program from the top down and stops, with a message worth reading, when it cannot go on.
S3, The Einstein On Your Computer - setting up the emulated Einstein that will check your work, and looking at your first disc image through its eyes.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.