Basic computing before programming — hardware, RAM, disk, terminal and keyboard explained for FP1 (and the grade that vanished when the program closed)

In my first weeks of FP1 I wrote a program that worked out the average of my grades. It worked beautifully: it told me “7.5” and I was delighted. The next day I opened it to check the average… and there was nothing. No average, no grades, not a trace. I thought Python “remembered” variables, as if they were files. It doesn’t: they live in RAM, and RAM is wiped the moment the program ends. That afternoon I learnt more computing than in the whole previous week.

When I started GCID I thought programming was just writing code. But I soon realised there are lots of basic computing concepts that everyone takes for granted and that nobody actually explains: what each part of the computer does, where your program is stored, what the terminal is or why you can’t find the curly braces on the keyboard. In this article I tell you what you need to have clear before your first line of Python, with no unnecessary jargon and with real programs to check it.

In a nutshell: Before programming it helps to know how a computer works: the CPU runs the instructions, RAM holds what is in use and the disk keeps what stays when you switch off. It also helps to understand that everything is stored as bytes (text, with encodings like UTF-8), how file paths work and how to use the terminal.

Before you start. For this article you don’t need to know how to program or have anything installed: having used a computer is enough. The Python programs that appear are there so you can see what happens when they run, not for you to understand every line yet (when it matters, I tell you what the line does). The route goes from the inside out, in three stretches: first, what hardware is and what software is; then, the three parts that explain how your programs behave (CPU, RAM and disk) and how text is stored as bytes; and finally what you’ll touch every day: files, paths, the terminal, the keyboard and the IDE. If you get lost at any point, go back to the grade that vanished: half the article can be explained with it.

Hardware vs software — the difference that always confuses

This is the first thing to get clear, because you’ll hear it constantly throughout the degree:

  • Hardware is everything physical, everything you can touch: the screen, the keyboard, the processor, the RAM, the disk. If it breaks, it gets repaired or the part is replaced.
  • Software is what you can’t touch: programs, the operating system, code. If it fails, it gets fixed or reinstalled.

When you program in Python you’re creating software. Your computer (hardware) runs it. But between your program and the hardware there are more layers than it seems:

The hardware and software layers From top to bottom: your programs (hello.py), application software (VS Code, the browser, the Python interpreter), system software (Windows, Linux, macOS) and the hardware (CPU, RAM, disk, keyboard and screen). The layers of your computerYour programshello.py, grade_average.py…what you write in FP1Application softwareVS Code, the browser, the Python interpreterprograms for specific tasksSystem softwareWindows, Linux (Fedora), macOSshares the hardware among allHardwareCPU · RAM · disk (SSD) · keyboard · screenwhat you can touchEach layer only talks to the one below: your .py asks the interpreter, which asks the OS, which asks the hardware.
When you program in Python you create the top layer; the others were already there.

Read the diagram from top to bottom. Your hello.py doesn’t talk directly to the processor: it asks the Python interpreter (an application), the interpreter asks the operating system, and the operating system shares the hardware among all the programs you have open. That’s why the same hello.py works on Windows, Linux and macOS: what changes are the layers underneath, not your code.

Check you’ve got it: you copy your hello.py to a laptop running Linux. What do you have to change in the code for it to work?

Nothing. Your program only talks to the layer right below it, the Python interpreter, and the interpreter understands the same thing on every system. What that laptop does need is a Python interpreter built for Linux, because that is the one that knows how to ask that operating system for things. The layers underneath change; yours doesn’t. The only nuance is outside the code: in the Linux terminal the command is usually python3 hello.py instead of python hello.py.

Basic computing before programming — what really matters

Before giving the parts their names, go back to my grades program and think how you would work out that average by hand. You need three things. Someone to do the sum: you. Somewhere to keep the 7, the 8 and the result in view while you work: a sheet of scrap paper on the desk. And somewhere to leave the 7.5 so you can look it up tomorrow: the notebook you keep in your backpack.

Now imagine that when you finish you clear the desk and throw the sheet away. If you hadn’t copied the 7.5 into the notebook, tomorrow you don’t have it. The sum was done correctly, but it only existed on the sheet. That is exactly what happened to my program, with one difference: on a computer the sheet throws itself away, without asking you, the moment the program ends.

Inside the computer those three things are three different parts, and now it is time to call them by their names: the one doing the sum is the CPU, the sheet is RAM and the notebook is the disk.

You don’t need to be a hardware engineer to program, but you do need to understand three parts, because each one explains a behaviour of your programs:

PartWhat it isWhat you notice when programming
CPU (processor)The brain: runs instructions one after another, billions per secondA program with lots of calculations takes longer
RAM (memory)Fast, temporary memory holding what’s in use right nowYour variables live here and vanish when the program ends
Disk (SSD or HDD)Permanent storage, slowerYour .py files and the data you save live here

The key is the difference between RAM and disk. I checked it with two programs run one after the other in the same folder. The first one computes an average and saves it to a file:

# a_ram.py: a variable lives in RAM; a file, on disk
grade1 = 7
grade2 = 8
average = (grade1 + grade2) / 2                      # (7 + 8) / 2 = 7.5, computed by the CPU and stored in RAM
print("Average computed:", average)

with open("notes.txt", "w", encoding="utf-8") as f:  # "w" = write: creates the file on disk
    f.write(f"average={average}\n")
print("Saved to notes.txt")

Output:

Average computed: 7.5
Saved to notes.txt

The maths: (7 + 8) / 2 = 15 / 2 = 7.5. The variable average is in RAM; on top of that, the with open(...) block creates notes.txt on disk and writes average=7.5 into it. Now another program, run afterwards, tries to use both things:

# b_after.py: another program, run afterwards. What still exists?
with open("notes.txt", encoding="utf-8") as f:       # the file is still on disk
    print("On disk:", f.read().strip())

print("In RAM:", average)                            # the variable died with the previous program

Output:

On disk: average=7.5
Traceback (most recent call last):
  File "b_after.py", line 5, in <module>
    print("In RAM:", average)                           # the variable died with the previous program
                     ^^^^^^^
NameError: name 'average' is not defined

The file part works: notes.txt is still on disk and we read it without trouble. But the variable average no longer exists: it died with the first program, and Python answers with a NameError (read the last line of the error: “name average is not defined”). That’s exactly what happened with my grades program.

RAM versus disk with a_ram.py While a_ram.py runs, the variables grade1, grade2 and average live in RAM, the CPU computes (7 + 8) / 2 = 7.5 and the program creates notes.txt on disk. When it ends, RAM is empty: b_after.py can read notes.txt but average raises NameError. Where everything lives while a_ram.py runsDisk (SSD)permanentRAMtemporaryCPUcomputesWhile it runsa_ram.pynotes.txt ← createdgrade1 = 7 grade2 = 8average = 7.5(7 + 8) / 2= 7.5When it ends (and b_after.py runs)a_ram.pynotes.txt   still here(empty)average → NameErrornothing to compute
RAM is wiped when the program ends; whatever you want to keep has to go into a file on disk.

The diagram sums up both phases. While a_ram.py runs, the CPU computes, RAM holds the variables and the disk receives notes.txt. When it ends, the RAM column is empty and only what was on disk survives.

The two runs, moment by moment

Let’s go through the two programs again, slowly, looking at what is in RAM and what is on disk at each moment. First, a detail I haven’t told you until now: a program saved on disk does nothing. To run it, the operating system copies it from the disk into RAM, and that is where the CPU reads its instructions one by one.

MomentIn RAMIn notes.txt (disk)Why
You type python a_ram.pyThe program, just loaded; no variables yetDoesn’t existThe operating system copies the program from the disk into RAM so the CPU can run it
grade1 = 7 and grade2 = 8grade1 and grade2Doesn’t existEach variable is a slot of RAM with a name
average = (grade1 + grade2) / 2grade1, grade2 and average (7.5)Doesn’t existThe CPU does the sum and leaves the result in RAM, not on disk
print("Average computed:", average)The same threeDoesn’t existprint only shows the value on the screen: it doesn’t save anything anywhere
with open(...) and f.write(...)The same three (and f, the open file)average=7.5It is the only instruction in the program that sends something to the disk
a_ram.py endsNothingaverage=7.5The operating system takes that RAM back for other programs; the disk is not touched
You type python b_after.pyThe new program; no variablesaverage=7.5Every run starts with a clean memory: it inherits nothing from the previous one
open(...) and f.read()The text that has just been readaverage=7.5The file was still on disk, and reading it copies it into RAM without deleting it
print("In RAM:", average)No averageaverage=7.5In this program nobody has created average: out comes the NameError

The row that explains my slip is the fourth: seeing the 7.5 on the screen made me believe it was “saved”, but print only shows it. The one that would have prevented it is the fifth.

Check you’ve got it: you delete notes.txt and run only b_after.py. Do you get the NameError again?

No: the program doesn’t even reach that line. Python runs from top to bottom and stops at the first error, and now the first one is on line 2: open looks for notes.txt on disk, doesn’t find it and you get FileNotFoundError: [Errno 2] No such file or directory: 'notes.txt'. If you run a_ram.py first, the file exists again, line 2 works and the error becomes the one on line 5, the NameError. They are two different errors for two different reasons: the first, because something is missing on disk; the second, because something is missing in RAM.

Thinking a variable “gets saved” when you close the program. Whatever you want to keep between runs has to go into a file (you’ll see it in depth in the FP1 topic on text files).

A typical student computer today has 8 or 16 GB of RAM and an SSD of 256 to 1000 GB. RAM is about a hundred times smaller than the disk, but far faster: that’s why the program works in RAM and only uses the disk to load and save.

Bits, bytes and why “ñ” takes twice the space

Everything a computer stores is bits (zeros and ones), grouped in eights into bytes. A kilobyte (KB) is 1000 bytes; a megabyte (MB), a million; a gigabyte (GB), a billion. And text? Each character becomes one or more bytes according to an encoding; the one used by your .py files is UTF-8. This program measures it:

# c_bytes.py: how many bytes each character takes in UTF-8 (the encoding of your .py files)
for text in ["a", "ñ", "€", "🐍", "Python"]:
    n = len(text.encode("utf-8"))                   # encode turns the text into bytes
    print(f"{text!r:10} -> {len(text)} character(s), {n} byte(s)")

Output:

'a'        -> 1 character(s), 1 byte(s)
'ñ'        -> 1 character(s), 2 byte(s)
'€'        -> 1 character(s), 3 byte(s)
'🐍'        -> 1 character(s), 4 byte(s)
'Python'   -> 6 character(s), 6 byte(s)

Notice: a takes 1 byte, but ñ takes 2, € takes 3 and the emoji takes 4, even though all four are a single character for Python (len counts characters; len(text.encode("utf-8")) counts bytes). "Python" is 6 letters without accents: 6 characters and 6 bytes.

And why don’t they all take the same space? Start with the bit: it can only tell two things apart, 0 or 1. With two bits there are already four combinations (00, 01, 10 and 11), and every bit you add doubles them. With the 8 bits of a byte you get 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256 combinations, so a byte can hold a number from 0 to 255 and nothing more.

Storing text is, then, storing numbers: each character has one. The a is 97, which in bits is written 01100001. From right to left, the positions are worth 1, 2, 4, 8, 16, 32, 64 and 128; the ones switched on are the 64, the 32 and the 1, and 64 + 32 + 1 = 97.

The problem is that the world has far more than 256 characters. UTF-8 solves it like this: the letters of the English alphabet, the digits and the basic signs (the first 128 numbers, from 0 to 127) take a single byte; for everything else it uses bytes from 128 upwards, which come in groups of two, three or four. You can see the numbers of any text with list(text.encode("utf-8")):

CharacterBytes in UTF-8How manyWhy
a971It is among the 128 basic ones: one byte is enough
ñ195, 1772It is not among the basic ones: it needs a group of two
€226, 130, 1723It is one of those that come in a group of three

This explains the warning in the box below. A program that reads the file with an old encoding, one byte per character, doesn’t know that 195 and 177 go together: it draws them separately, and in that encoding 195 is à and 177 is ±. That is where the famous ñ comes from.

Check you’ve got it: what do len("año") and len("año".encode("utf-8")) give?

They give 3 and 4. For Python the word (Spanish for “year”) has three characters, and that is what the first len counts. In bytes, the a takes 1, the ñ takes 2 and the o takes 1: 1 + 2 + 1 = 4, which are the bytes 97, 195, 177 and 111. If the file contained only that word, it would weigh 4 bytes, not 3.

If you open a file and see things like ñ instead of ñ, it was written in UTF-8 and is being read with another encoding. That’s why, in Python, you should always write encoding="utf-8" when opening text files, as in the programs above.

System software vs application software

Your computer has two big layers of software (the two in the middle of the first diagram):

  • System software: the operating system (Windows, macOS, Linux). It’s the go-between for the hardware and your programs: it decides which program uses the CPU at each moment, how much RAM each one gets and who can read each file.
  • Application software: the programs you use to do specific things. VS Code is application software. The Python interpreter too. The browser too.

As a GCID student you’ll mostly work on Windows, but in IC2 you’ll meet Linux (Fedora). If you want a head start, read Linux for students and set up a virtual machine with the guide to install Fedora on VirtualBox.

File organisation — do this now

It looks trivial but it’s one of the most practical pieces of advice I can give you: organise your code files from day one. During the degree you’ll have dozens of .py files, and if they’re all on the desktop or in Downloads, within two weeks you won’t find anything. A simple structure that works:

GCID
├── FP1
│   ├── topic_variables
│   │   ├── grade_average.py
│   │   └── bmi.py
│   └── topic_conditionals
└── IC2

Three rules that will save you trouble:

  1. No spaces or accents in names of code folders and files: topic_variables, not The variables topic. In the terminal, a space separates words and forces you to use quotes.
  2. Turn on file extensions in Windows File Explorer (View → Show → File name extensions). That way you’ll see whether your file is hello.py or hello.py.txt.
  3. A name that says what it does: grade_average.py makes sense a month later; test2_final_good.py doesn’t.

Paths: each file’s address

Every file has a path, its address on the disk. On Windows, the absolute path starts with the drive letter: C:\Users\Sergio\GCID\FP1\topic_variables\grade_average.py. A relative path counts from the folder you’re in: if you’re already in C:\Users\Sergio\GCID\FP1, the same file is topic_variables\grade_average.py. And .. means “the folder above”.

ExtensionWhat it isWhat opens it
.pyPython programVS Code, python file.py
.ipynbJupyter notebookVS Code with Jupyter
.csvData in comma-separated columnsVS Code, Excel, pandas
.txtPlain textAny editor
.c / .javaC / Java code (IC2, FP2)VS Code

Windows separates folders with \ and Linux with /. Python also accepts / on Windows, so in your programs you can write "data/grades.csv" and it will work on both systems.

The terminal — your new best friend

The terminal (also called the console or command line) is a window where you give orders to the operating system by typing, without the mouse. It’s intimidating at first, but you’ll use it constantly: to run programs, install libraries, compile C and move around Linux in IC2.

On Windows you open it by searching for cmd (Command Prompt) or PowerShell in the Start menu. These are the basic commands you need from the start (they’re Windows commands, so I describe them; on Linux almost all of them change name):

I want to…Windows (cmd / PowerShell)Linux (bash)
See which folder I’m incd (cmd) / pwd (PowerShell)pwd
Go into a foldercd topic_variablescd topic_variables
Go up to the folder abovecd ..cd ..
See the filesdirls
Create a foldermkdir FP1mkdir FP1
Clear the screenclsclear
Run a Python programpython grade_average.pypython3 grade_average.py
See the Python versionpython --versionpython3 --version

If you followed the guide to install Python on Windows, you already used the terminal to check it worked. That’s exactly what it’s for.

Press Tab while typing a folder or file name and the terminal completes it for you. Type cd top + Tab and you get cd topic_variables. Less typing and zero typos.

A whole terminal session, command by command

The table of commands is easier to understand by using it. Behind all of them there is one idea: the terminal is always “inside” a folder, the current folder, and everything you type is interpreted from there. On Windows you always have it in view, written just to the left of where you type (C:\Users\Sergio>). This is a complete session with the folder structure from before:

You typeCurrent folder afterwardsWhy
(you open the terminal)C:\Users\SergioWhen it opens, the terminal usually starts in your user folder
cd GCIDC:\Users\Sergio\GCIDGCID is a relative path: it is looked up inside the current folder
cd FP1\topic_variablesC:\Users\Sergio\GCID\FP1\topic_variablesYou can go down two folders at once by separating them with \
dirThe samedir doesn’t move you: it lists what is here, grade_average.py and bmi.py
python grade_average.pyThe sameA bare name is also a relative path, and the file is right here: it runs
cd ..C:\Users\Sergio\GCID\FP1.. is the folder above
python grade_average.pyThe sameError: there is no grade_average.py in FP1. The file hasn’t moved; you have
python topic_variables\grade_average.pyThe sameNow the relative path does lead from where you are to the file: it runs

The error in the second-to-last row ends in [Errno 2] No such file or directory and it is, by far, the one you’ll see most in your first weeks. It almost never means your program is wrong: it means the terminal is in another folder.

When you get that error, before touching the code look at two things: which folder you are in (it is shown to the left of where you type) and what is in it (dir). If your file isn’t in the list, the problem is the folder, not the program.

Check you’ve got it: you are in C:\Users\Sergio\GCID\FP1\topic_variables and you type cd ..\... Which folder do you end up in? And which command would take you from there, in one go, into topic_conditionals?

You end up in C:\Users\Sergio\GCID. Each .. goes up one folder: the first takes you from topic_variables to FP1 and the second, from FP1 to GCID. To go down to the other folder you type cd FP1\topic_conditionals, a relative path that starts at GCID, which is where you are. With the absolute path, cd C:\Users\Sergio\GCID\FP1\topic_conditionals, you would get there from anywhere, because an absolute path doesn’t depend on the current folder.

Special characters you’ll type constantly in code

The FP1 notes include a table of special characters that are essential for programming. These are the ones you’ll use most, and what for:

CharacterNameIn Python it’s used forExample
( )ParenthesesCalling functions, grouping mathsprint("hello")
[ ]Square bracketsLists and indexes[1, 2, 3]
{ }Curly bracesDictionaries and f-strings{"key": "value"}
" " and ' 'QuotesText (strings)"Sergio"
:ColonAfter if, for, defif x > 0:
#HashComments# this doesn't run
_UnderscoreVariable namesgrade_average
=EqualsAssignmentx = 5
==Double equalsComparisonx == 5
\BackslashSpecial characters in text"\n" (new line)

On a Spanish keyboard (the one most of us at ULPGC use), several of these aren’t obvious. Many websites give combinations that are wrong, so here they are drawn key by key:

Programming symbols on the Spanish keyboard With AltGr: brackets on the `^ and +* keys, braces on ´¨ and ç, hash with AltGr+3, backslash with º, pipe with AltGr+1, at sign with AltGr+2 and tilde with AltGr+4. With Shift: parentheses on 8 and 9, equals on 0, double quotes on 2, colon on the full stop, underscore on the hyphen, slash on 7 and asterisk on +. Programming symbols on a Spanish keyboardWith AltGr (the key to the right of the space bar)[`^ key]+* key{´¨ key}ç key#AltGr+3\º key|AltGr+1@AltGr+2~AltGr+4With Shift(Shift+8)Shift+9=Shift+0“Shift+2:Shift+._Shift+-/Shift+7*Shift++‘no ShiftThe `^ and +* keys sit to the right of P; ´¨ and ç to the right of Ñ.
Top row: what you get with AltGr; bottom row: with Shift. Brackets and braces are the hardest at first.

The top row shows what you get with AltGr (the key to the right of the space bar): square brackets [ ] are on the two keys to the right of P (the grave/circumflex accent key and the + key) and curly braces { } on the two to the right of Ñ (the acute accent key and ç). The hash is AltGr + 3 and the backslash AltGr + º (the top-left key). The bottom row shows Shift: parentheses with 8 and 9, equals with 0 and the colon on the full stop key. On a US or UK keyboard most of these are printed on the keys themselves. Learn them by heart: you’ll type them thousands of times.

Mixing up = and ==. x = 5 stores 5 in x; x == 5 asks whether x is 5 and answers True or False. Writing if x = 5: gives a SyntaxError as soon as you run it.

The IDE — where you write your code

An IDE (Integrated Development Environment) is the program where you write and run your code. We use VS Code, which I explain step by step in configure VS Code for Python.

What does an IDE do that Notepad doesn’t? It colours the code so it’s easier to read, detects errors as you type, autocompletes names, lets you run the program without leaving the editor and debug it line by line. And it doesn’t add .txt to your files without telling you.


Exam-style quiz

Now test yourself as in the exam. The FP1 quizzes look like this: 15 questions in 20 minutes (16 in 30 in the Sequences one), almost all single choice (each wrong answer subtracts a third of what the question is worth) and many «what does this code print?», with the odd fill in the gaps, matching or true or false. Here are 13 original questions on basic computing. Answer without running anything, press Check and read the explanation for each one. These questions are also the question bank for the FP1 theory mock exam, which will mix them with those from the other topics.

Question 1Single choice

You are writing an assignment and the power goes off before you save. Why do you lose the last thing you wrote?

  1. It was only in RAM, which is wiped when the power goes
  2. It was on the disk, but the disk is formatted when it switches off
  3. The CPU kept it in its registers and sends it to the internet on shutdown
  4. The operating system deletes files that are not closed properly
Solution

Answer: It was only in RAM, which is wiped when the power goes

While you work, the open document lives in RAM, which is fast but volatile. Saving copies it to the disk (or SSD), which is slower but persistent: it keeps the data without power.

Question 2Match

Match each component with what it does:

CPU
RAM
Disk or SSD
Operating system

Definitions:

  • Holds the programs and data in use right now
  • Shares the CPU, memory and devices among programs
  • Keeps files even when the computer is off
  • Turns Python code into a text document
  • Runs the instructions of programs
Solution
  • CPU → Runs the instructions of programs
  • RAM → Holds the programs and data in use right now
  • Disk or SSD → Keeps files even when the computer is off
  • Operating system → Shares the CPU, memory and devices among programs

The CPU does the work; RAM is its desk (fast and volatile); the disk is the filing cabinet (slow and persistent); and the operating system organises everything so that several programs can live together.

The extra definition does not belong to any component.

Question 3Multiple · wrong ticks subtract

Which of these are input devices?

  1. Keyboard
  2. Mouse
  3. Microphone
  4. Monitor
  5. Printer
Solution

Answer: Keyboard · Mouse · Microphone

Input = from the world into the computer (keyboard, mouse, microphone, scanner). Output = from the computer to you (monitor, speakers, printer). Remember that in multiple choice wrong ticks subtract: do not tick just in case.

Question 4Short answer

How many bits are there in 3 bytes? Write only the number.

Solution

Answer: 24

A byte is 8 bits, so 3 × 8 = 24 bits. A bit is a single 0 or 1; with one byte (8 bits) you can represent 2⁸ = 256 different values.

Question 5Single choice

Which decimal number does the binary 1011 represent?

  1. 11
  2. 13
  3. 1011
  4. 7
Solution

Answer: 11

From right to left, the positions are worth 1, 2, 4 and 8. In 1011 the 8, the 2 and the 1 are on: 8 + 2 + 1 = 11.

Question 6True or false

True or false?

  1. The operating system is a program, even if a very special one.
  2. RAM keeps its data when you switch the computer off.
  3. A path like C:\Users\ana\notes.txt says which folder a file is in.
  4. The terminal only exists on Linux; Windows does not have one.
Solution
  • T — The operating system is a program, even if a very special one.
  • F — RAM keeps its data when you switch the computer off.
  • T — A path like C:\Users\ana\notes.txt says which folder a file is in.
  • F — The terminal only exists on Linux; Windows does not have one.

The OS is software: it is loaded at start-up and manages everything else. RAM is volatile. A path is the chain of folders down to the file. And Windows has a terminal too (CMD and PowerShell), just like macOS and Linux.

Question 7Single choice

What is an IDE, such as VS Code or PyCharm?

  1. A program to write, run and debug code in one place
  2. The language Python programs are written in
  3. A computer component that speeds programs up
  4. A special folder where Python keeps its files
Solution

Answer: A program to write, run and debug code in one place

IDE stands for Integrated Development Environment. You could program with Notepad and the terminal, but the IDE warns you about errors, colours the code and runs it with one button.

Question 8Fill in the gaps

Complete the sentence:

To run a program, the operating system copies it from the ____ into ____, and the ____ runs its instructions one by one.

Words:

  • printer
  • RAM
  • screen
  • disk
  • CPU
Solution

To run a program, the operating system copies it from the disk into RAM, and the CPU runs its instructions one by one.

The program is stored on the disk, but the CPU only works with what is in RAM. That is why opening a big program takes a moment: it has to be copied first.

Question 9Single choice

What are square brackets [ ] mainly used for in Python?

  1. To write lists and access positions, as in grades[0]
  2. To write comments
  3. To group the code of an if
  4. To write text
Solution

Answer: To write lists and access positions, as in grades[0]

It is worth learning where [ ], { }, # and the quotes are on your keyboard: you will type them hundreds of times. On a Spanish keyboard the brackets need Alt Gr plus the two keys to the right of P.

Question 10Single choice

What is the difference between a file and a folder?

  1. A file holds data (a text, a photo, a program); a folder groups files and other folders
  2. None: they are two names for the same thing
  3. The file is in RAM and the folder on the disk
  4. Folders only exist on Windows
Solution

Answer: A file holds data (a text, a photo, a program); a folder groups files and other folders

The OS file system organises the disk as a tree of folders (directories) that contain files. When, in the files topic, you write open('data.txt'), Python will look for that file in the folder you run the program from.

Question 11Order

Put in order what happens from pressing the power button to writing your first program:

  1. You log in and the desktop appears
  2. The firmware (BIOS or UEFI) runs and checks the hardware
  3. The operating system is loaded from the disk into RAM
  4. You open the IDE
  5. You write the program and save it to the disk
Solution

Correct order:

  1. The firmware (BIOS or UEFI) runs and checks the hardware
  2. The operating system is loaded from the disk into RAM
  3. You log in and the desktop appears
  4. You open the IDE
  5. You write the program and save it to the disk

First the small firmware program starts, finds the operating system and loads it into memory. With the OS running you can open applications such as the IDE. And what you write is not safe until you save it to the disk.

Question 12Single choice

What happens to the value of grade when this program ends?

grade = 7.5
print(grade)
  1. It disappears: variables live in RAM while the program runs
  2. It is saved to the disk automatically
  3. It stays on the screen for ever
  4. It is saved inside the .py file itself
Solution

Answer: It disappears: variables live in RAM while the program runs

When the program runs, Python sets aside room in RAM for grade. When the program ends, that memory is freed and the value is gone. If you want it to last between runs, you have to write it to a file (the last FP1 topic).

Question 13Single choice

What happens if you type python3 hello.py in the terminal?

  1. The Python interpreter reads hello.py and runs its instructions
  2. A new empty file called hello.py is created
  3. The IDE opens with the file
  4. The file is deleted after running it
Solution

Answer: The Python interpreter reads hello.py and runs its instructions

The terminal runs commands: python3 is the program (the interpreter) and hello.py the file you give it. If the file is not in the current folder, you will see an error like No such file or directory.

Watch it step by step in Python Tutor

pythontutor.com runs your code line by line and draws the variables in memory at each moment: it’s the most direct way to “see” RAM. Choose Python 3, paste this program and click Visualize Execution:

# Python Tutor: variables appear in RAM (Frames) while the program runs
grade1 = 7
grade2 = 8
average = (grade1 + grade2) / 2

subjects = ["FP1", "Calculus"]
subjects.append("Algebra")                        # the list grows: it is the same list, not a copy

def round1(x):
    result = round(x, 1)                          # 'result' only exists while the call lasts
    return result

average = round1(average)
print("Average:", average, "in", len(subjects), "subjects")

Output:

Average: 7.5 in 3 subjects

What to watch step by step:

  1. In the first steps, the Frames column shows grade1, grade2 and average (7.5): those little boxes are your variables in RAM.
  2. When subjects is created, the list is drawn on the right (Objects) and the variable points to it with an arrow.
  3. With append, the same list grows to three items: no new list is created.
  4. When round1 is called, a new frame appears with x and result; as soon as the call ends, it disappears. It’s the same RAM idea, on a small scale.
  5. At the end, average is 7.5 and len(subjects) is 3, which is exactly what the output prints.

Summary — the essentials before programming

ConceptIn one sentence
Hardware / softwareWhat you touch / programs and code
LayersYour program → applications → operating system → hardware
CPURuns the instructions
RAMHolds variables while the program runs; wiped when it ends
DiskKeeps your .py files and data permanently
Byte and UTF-88 bits; ñ takes 2 bytes, a takes 1
PathA file’s address: absolute (from C:\) or relative
TerminalTyped orders to the system: cd, dir, python file.py
IDEWhere you write, run and debug (VS Code)

Three ideas to take away:

  1. RAM forgets, the disk remembers: whatever you want to keep goes into a file.
  2. Organise and name things well from day one: folders per subject, no spaces or accents, extensions visible.
  3. The terminal and the keyboard are working tools: learn five commands and where [ ] and { } are, and you’ll move twice as fast.

With all this clear, you have all the context you need to start. The next step is to install Python on Windows and then configure VS Code, if you haven’t done that yet.

Next step: exercisesBasic computing — exercises with a pendrive, folder paths and bytes with accents (and the grades.txt that «didn’t exist» in the lab)

Did this article help you? Here is how you can support SergioLearns →