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

My first FP1 lab session gave me something I laugh about now. At home, my program read grades.txt with no trouble. In the lab I opened it from the terminal, typed python3 fp1/read.py and got a huge FileNotFoundError. The file was right there, in the same folder as the program. It took me ten minutes to understand that what mattered was not where the program was, but which folder I was running it from. (This anecdote is not real: it is the kind of thing that happens in the first week.)

This article is the hands-on part of the basic computing theory. You do not need to know how to program here: the Python programs are three or four lines long and they are only there to check sums you can do by hand. What you take away are three things you will use all year: thinking in sizes (bytes, MB, GB), moving around folders with the terminal and understanding why an ñ «weighs» more than an n.

How to use this article

Do each level with pen and paper first (or with the terminal, in level 2) and only then look at the solution. The three levels go from easier to harder:

LevelWhat you practiceWhat you need
1 · BasicStorage units and whole divisionMultiplying and dividing
2 · IntermediateAbsolute and relative paths, cd, ls, mkdir, pwdA terminal (Linux, macOS or the one in VS Code)
3 · ChallengeBinary and text as bytes (UTF-8)Knowing what a bit and a byte are

Then come three «What’s wrong here?» fragments, the explained solutions, an exam-style quiz like the lab one and the cheat sheet to have it all on one page.

If you have never opened a terminal, in VS Code it is under Terminal → New Terminal. On Windows, almost all the Linux commands of level 2 work in PowerShell (cd, ls, mkdir, pwd); in CMD, ls is called dir.

Level 1 · Basic: what fits on a pendrive

You have a 16 GB pendrive and you want to store the photos and videos from a trip. Each phone photo takes 3.5 MB and each five-minute video, 850 MB. The operating system counts 1 GB = 1024 MB and 1 MB = 1024 × 1024 bytes.

Work out:

  1. How many MB the pendrive has.
  2. How many photos fit if you only store photos (whole photos: half a photo does not count).
  3. How much space is left after storing 5 videos, and how many photos fit in that gap.
  4. How many bytes one photo takes.

Expected output of the program that checks your sums:

Capacity: 16384 MB
Photos that fit on their own: 4681
Space after 5 videos: 12134 MB
Photos that fit afterwards: 3466
One photo in bytes: 3670016

For «how many fit whole» you do not want normal division (/), which gives decimals, but whole division (//), which keeps the part below.

Level 2 · Intermediate: moving around your degree folders

With the terminal you are going to create this structure inside your home folder (/home/sergio in the example):

gcid/
├── fp1/
│   ├── notes/
│   └── practicals/
│       └── grades.py
└── ic2/

Using terminal commands, and without the file explorer:

  1. Create the folders gcid/fp1/practicals, gcid/fp1/notes and gcid/ic2 with a single command.
  2. Go into gcid/fp1, check where you are and list what is there.
  3. Go into practicals, create an empty file grades.py and list again.
  4. Without typing /home/sergio again, jump to ic2 with a relative path and check where you are.
  5. List what is in the folder above (gcid) without moving.
  6. Jump to notes with an absolute path.

What you should see when you run pwd in steps 2, 4 and 6: /home/sergio/gcid/fp1, /home/sergio/gcid/ic2 and /home/sergio/gcid/fp1/notes (with your user instead of sergio).

.. is «the folder above». A path that starts with / is absolute (it is read from the root); one that does not is relative (it is read from where you are).

Level 3 · Challenge: numbers in binary and text in bytes

Two questions that look different but are the same idea: everything is stored as bits.

  1. Convert 2026 to binary. How many bits are needed? Check that converting back to decimal gives 2026.
  2. The Spanish phrase Mañana, café en Gáldar («Tomorrow, coffee in Gáldar») has 22 characters. How many bytes does it take when stored in UTF-8? Which bytes make up the ñ and which one makes up the a?

Expected output:

2026 in binary: 11111101010
Bits needed: 11
Back to decimal: 2026
Characters: 22
Bytes in UTF-8: 25
The ñ in bytes: b'\xc3\xb1'
The a in bytes: b'a'

In UTF-8, «English» letters (no accents) take 1 byte. The ñ and accented vowels take 2. Count how many there are in the phrase.

What’s wrong here?

Three first-week mistakes. Try to guess what happens before you read the explanation.

Fragment 1: the grade that was gone the next day

A program stores your grade:

# First time: I store the grade in a variable
grade = 8.5
print("Grade saved:", grade)

And the next day, another program (or the same one, run again) tries to read it:

# The next day, another program (or the same one, run again) wants the grade
print("Your grade was:", grade)

This is what comes out:

Traceback (most recent call last):
  File "check.py", line 2, in <module>
    print("Your grade was:", grade)
NameError: name 'grade' is not defined

What’s wrong: variables live in RAM while the program runs. When it ends, the operating system frees that memory and grade no longer exists. For a piece of data to survive you have to write it to the disk, in a file:

# Fix: the grade is written to a file on the disk, which does survive when the program closes
grade = 8.5
with open("grade.txt", "w", encoding="utf-8") as f:
    f.write(str(grade))
print("Grade saved in grade.txt")
# Another day: it is read from the file
with open("grade.txt", encoding="utf-8") as f:
    grade = float(f.read())
print("Your grade was:", grade)
Your grade was: 8.5

You will see with open(...) in depth in the last FP1 topic, Text files. Here only the idea matters: RAM = while the program lasts; disk = for ever (until you delete it).

Fragment 2: the grades.txt that «didn’t exist»

You have read.py and grades.txt in the same folder, gcid/fp1. read.py opens "grades.txt" with a relative path. Look at what happens when you run it from two different places:

$ cd gcid
$ python3 fp1/read.py
Traceback (most recent call last):
  File "/home/sergio/gcid/fp1/read.py", line 1, in <module>
    with open("grades.txt", encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'grades.txt'
$ cd fp1
$ python3 read.py
FP1: 8.5

What’s wrong: a relative path like "grades.txt" is looked for in the working directory (the folder you are in at the terminal, the one pwd shows), not in the folder where the program is. From gcid, Python looks for gcid/grades.txt, which does not exist. From gcid/fp1, it finds it. It is exactly the anecdote from the start.

Thinking that FileNotFoundError means the file does not exist. Often it does exist, but Python is looking for it in another folder. First of all, run pwd and ls.

Fragment 3: the quotes copied from Word

You copy an example from a PDF or a Word document and paste it into your editor:

print(“Hello, FP1”)
  File "quotes.py", line 1
    print(“Hello, FP1”)
          ^
SyntaxError: invalid character '“' (U+201C)

What’s wrong: Word and many PDFs turn straight quotes " into typographic quotes “ ”. For Python they are different characters (U+201C and U+201D) and they cannot be used to write text. The fix is to type them with the keyboard, in your editor:

print("Hello, FP1")
Hello, FP1

If the error says invalid character and shows you a symbol that looks normal, suspect something copied and pasted: curly quotes, long dashes (—) or odd spaces.

Solutions

Level 1 solution

The approach: before dividing anything, put everything in the same unit. The statement mixes GB (the pendrive) and MB (the photos and videos), and the obvious move would be to divide 16 by 3.5 straight away: you get 4.57, which means nothing, because you’re sharing gigabytes among megabytes. That’s why the first step is to turn the pendrive into MB (16 × 1024) and, from there on, every calculation speaks the same language.

After that, each question in the statement is one operation: «how many fit» is an integer division, «how much is left» is a subtraction and «how many bytes» is multiplying by 1024 twice again. The videos go first because the statement says so: whatever is left free is the gap for the photos.

# Level 1: how much fits on the pendrive? (units: 1 GB = 1024 MB, as the operating system counts)
pendrive_gb = 16                        # what the box says
capacity_mb = pendrive_gb * 1024        # convert to MB: 16 × 1024
photo_mb = 3.5                          # one photo from the phone
video_mb = 850                          # one 5-minute video
videos = 5                              # videos you want to store first

max_photos = capacity_mb // photo_mb    # // = how many fit whole (no half photos)
free_mb = capacity_mb - videos * video_mb
photos_left = free_mb // photo_mb

print("Capacity:", capacity_mb, "MB")
print("Photos that fit on their own:", int(max_photos))
print("Space after", videos, "videos:", free_mb, "MB")
print("Photos that fit afterwards:", int(photos_left))
print("One photo in bytes:", int(photo_mb * 1024 * 1024))
Capacity: 16384 MB
Photos that fit on their own: 4681
Space after 5 videos: 12134 MB
Photos that fit afterwards: 3466
One photo in bytes: 3670016

Let’s check it by hand, step by step:

StepSumResult
Capacity in MB16 × 102416,384 MB
Photos on their own16,384 // 3.54681 (4681.1 → the whole part)
What 5 videos take5 × 8504250 MB
Free space16,384 − 425012,134 MB
Photos afterwards12,134 // 3.53466 (3466.9 → 3466)
One photo in bytes3.5 × 1024 × 10243,670,016 bytes

Notice two decisions:

  • // and not /. 16384 / 3.5 gives 4681.14…, and you cannot store 0.14 of a photo. // rounds down, which is exactly what the task asks for (if we rounded up to 4682, the last photo would not fit).
  • int(...) when printing. Since photo_mb is a number with decimals, 16384 // 3.5 returns 4681.0. The int removes that .0 so that it reads better.

If the box says «16 GB», the operating system will show you about 14.9: the manufacturer counts 1 GB = 1000 MB and Windows or Linux count 1024. Nothing is missing; they just count differently.

What would happen if you stored the photos first and then wanted the videos?

With the 4681 photos inside, they take up 4681 × 3.5 = 16 383.5 MB and 16 384 − 16 383.5 = 0.5 MB are left free. A video takes 850 MB, so 0.5 // 850 = 0: not a single one fits.

The order in which you fill the pendrive changes the result. That’s why the statement sets the videos first: the big things first and, in the gap that’s left, the small ones, which fit in more easily.

Level 2 solution

The approach: before typing commands, look at the tree in the statement and, at every step, ask yourself just one question: which folder am I starting from? A relative path depends on the answer; an absolute one doesn’t.

The obvious way to create the folders would be one by one, or typing mkdir gcid/fp1/practicals on its own. That command fails, because gcid and fp1 don’t exist yet and mkdir doesn’t create the folders in between unless you ask it to: hence the -p. And to move around, the obvious move would be to always type the full path from /home/sergio. It works, but step 4 asks for the relative one on purpose: on another computer your user has a different name, and the relative path still works.

This is the whole terminal session, with what really comes out:

$ mkdir -p gcid/fp1/practicals gcid/fp1/notes gcid/ic2
$ cd gcid/fp1
$ pwd
/home/sergio/gcid/fp1
$ ls
notes
practicals
$ cd practicals
$ touch grades.py
$ ls
grades.py
$ cd ../../ic2
$ pwd
/home/sergio/gcid/ic2
$ ls ..
fp1
ic2
$ cd /home/sergio/gcid/fp1/notes
$ pwd
/home/sergio/gcid/fp1/notes

What each command does:

  • mkdir -p gcid/fp1/practicals gcid/fp1/notes gcid/ic2 creates the three folders at once. The -p option also creates any missing folders in between (gcid and gcid/fp1) and does not complain if they already exist.
  • cd gcid/fp1 goes into fp1 with a relative path (it does not start with /), and pwd (print working directory) confirms where you are.
  • ls lists what is there. Here they come out one under the other; in your terminal they may come out on the same line.
  • touch grades.py creates an empty file (or updates its date if it already exists).
  • cd ../../ic2 is the relative path of step 4: the first .. goes up to fp1, the second to gcid, and then down into ic2.
  • ls .. lists the folder above without moving.
  • cd /home/sergio/gcid/fp1/notes is the absolute path: it works from any folder because it starts at the root.
Paths in the folder treeTree with /home/sergio, gcid, fp1 (notes and practicals with grades.py) and ic2. The relative path ../../ic2 goes up two levels from practicals and down into ic2.Paths in the folder tree/home/sergiogcidfp1ic2notespracticalsgrades.py....ic2Absolute (starts at /):/home/sergio/gcid/ic2Relative from practicals:cd ../../ic2.. goes up one level(×2: fp1, gcid)and down into ic2pwd →/home/sergio/gcid/ic2
From practicals, ../../ic2 goes up twice (to fp1 and to gcid) and down into ic2; the absolute path works from any folder.

Look at the drawing: the coral line is the path of ../../ic2. The absolute path (on the right) does not depend on where you are; the relative one does.

cd on its own takes you to your home folder, cd - takes you back to the previous folder and the Tab key completes folder names. With Tab you will hardly ever mistype a path.

What would happen if in step 4 you typed cd ../ic2?

You’re in practicals. The .. goes up to fp1 and looks for an ic2 folder there, which doesn’t exist: the terminal answers cd: ../ic2: No such file or directory and you stay where you were, in practicals.

Count the levels: from practicals to gcid there are two jumps up, so you need two ... If in doubt, run pwd before typing the path.

Level 3 solution

The approach: for the binary, the obvious method taught at school is to divide by 2 again and again and read the remainders backwards. It works, but here the solution goes by powers: find the biggest one that fits in 2026 (1024) and keep subtracting. That way you see at a glance how many bits you need, because 1024 is position number 11 counting from the right.

For the bytes, the obvious move would be to think that each character is one byte and answer 22. The right approach is to split the characters into two groups: the «English» ones, which take 1 byte, and the ñ and the accented vowels, which take 2. You count the ones in the second group (3) and add them separately.

# Level 3: numbers in binary and text in bytes
number = 2026
binary = bin(number)[2:]              # bin() gives '0b11111101010': we drop the '0b'
print(number, "in binary:", binary)
print("Bits needed:", len(binary))
print("Back to decimal:", int(binary, 2))

text = "Mañana, café en Gáldar"
print("Characters:", len(text))
print("Bytes in UTF-8:", len(text.encode("utf-8")))
print("The ñ in bytes:", "ñ".encode("utf-8"))
print("The a in bytes:", "a".encode("utf-8"))
2026 in binary: 11111101010
Bits needed: 11
Back to decimal: 2026
Characters: 22
Bytes in UTF-8: 25
The ñ in bytes: b'\xc3\xb1'
The a in bytes: b'a'

The binary of 2026. Each position is worth twice the one on its right: 1, 2, 4, 8… 1024. For 2026 these are switched on: 1024 + 512 + 256 + 128 + 64 + 32 + 8 + 2 = 2026, that is, 11111101010: 11 bits (with 10 bits you would only reach 1023). bin() returns '0b11111101010'; the [2:] removes the 0b prefix, which only means «this is binary». int(binary, 2) goes back the other way.

The bytes of the text. The phrase has 22 characters, but three of them (ñ, é and á) take 2 bytes each in UTF-8: 22 + 3 = 25 bytes. len(text) counts characters; len(text.encode("utf-8")) counts bytes. The text stays in Spanish on purpose: English text without accents would give the same number of characters and bytes.

Characters versus bytes in UTF-8The Spanish word Mañana has 6 characters and takes 7 bytes: the ñ takes 2 bytes (c3 b1). The whole phrase, 22 characters and 25 bytes.Characters versus bytes in UTF-8characterbyte(s)M4da61ñc3b1a61n6ea61len("Mañana") = 6len("Mañana".encode()) = 7«Mañana, café en Gáldar» = 22 characters → 25 bytes (ñ, é and á take 2)
Letters without accents take 1 byte; ñ and accented vowels take 2. That is why len() and len(text.encode()) differ.

In the drawing, the ñ (coral) needs two boxes: c3 and b1, which is what Python shows as b'\xc3\xb1'. The a fits in a single one, and since it is a «normal» character, Python shows it as it is: b'a'.

If you open a file saved in UTF-8 with another encoding, those two bytes are read as two different characters and «Mañana» comes out as «Mañana». That is why in FP1 you will always write encoding="utf-8" when opening files.

How many bits would 2047 need? And 2048?

With 11 bits the biggest number is 11111111111, which is 2047 (1024 + 512 + … + 1, or 2048 − 1). So 2047 fits in exactly 11 bits.

2048 is exactly 2¹¹: in binary it’s a 1 followed by eleven zeros, 100000000000, and it needs 12 bits. It’s the same idea as the «with 10 bits you would only reach 1023» above: each new bit doubles the range.

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.

FP1 exam coming up?The 14 cheat sheets, the three solved practicals and a 14-day plan, in a free PDF.See the pack

Watch it step by step in Python Tutor

Python Tutor runs the code line by line and draws each variable in its box. Choose Python 3, paste this program (the level 1 sum, without text) and press Visualize Execution:

pendrive_gb = 16
capacity_mb = pendrive_gb * 1024
photo_mb = 3.5
photos = capacity_mb // photo_mb
video_mb = 850
free_mb = capacity_mb - 5 * video_mb
photos_after = free_mb // photo_mb
print(int(photos), int(photos_after))
4681 3466

What to watch (the number is the line that has just run, the one the red arrow marks):

  1. Line 1: the box pendrive_gb appears with 16. Before that line, the variable did not exist: that is how a piece of data «lives» in RAM.
  2. Line 2: capacity_mb is worked out with the value pendrive_gb already had (16 × 1024 = 16384).
  3. Line 4: photos is 4681.0, with .0: dividing by a number with decimals gives a float, even if you use //.
  4. Line 7: photos_after uses free_mb (12134), worked out on the line before. The order of the lines matters.
  5. At the end: the program finishes and all the boxes disappear. It is fragment 1 of «What’s wrong here?» seen live.

Cheat sheet: Basic computing

The essentials in 30 seconds: the CPU runs things, RAM holds what is in use (and is wiped when you switch off or close the program), the disk keeps things for ever. Everything is bits; 8 bits = 1 byte. Absolute paths start with /; relative ones are read from the current folder (pwd).

Units

I want to…SumResult
Convert GB to MBGB × 102416 GB = 16,384 MB
Convert MB to bytesMB × 1024 × 10243.5 MB = 3,670,016 B
Know how many fit wholetotal // size16,384 // 3.5 = 4681
Know how many values fit in n bits2ⁿ8 bits → 256

Terminal (Linux, macOS, PowerShell)

I want to…CommandResult
Know where I ampwd/home/sergio/gcid/fp1
See what is therels (in CMD, dir)notes practicals
Go into a foldercd practicalsrelative path
Go up one levelcd ..the folder above
Go to my home foldercd/home/sergio
Create folders (with the ones in between)mkdir -p a/b/cthree folders
Create an empty filetouch grades.pygrades.py
Run a programpython3 program.pyit is looked for in the current folder

Python to check things

I want…CodeResult
A number in binarybin(2026)[2:]'11111101010'
From binary to decimalint("1011", 2)11
The characters of a textlen("Mañana")6
The bytes in UTF-8len("Mañana".encode("utf-8"))7

Symptom → likely cause

SymptomLikely cause
NameError with a variable from «last time»Variables do not survive when the program closes: store it in a file
FileNotFoundError and the file does existYou are running from another folder: check pwd
SyntaxError: invalid character '“'Curly quotes copied from Word or a PDF
«Mañana» instead of «Mañana»The file was read with another encoding: use encoding="utf-8"
The pendrive «has less» than the box saysThe manufacturer counts 1000 and the operating system, 1024

Before you hand in, ask yourself:

  1. Am I in the right folder (pwd) before running?
  2. Have I saved the file (Ctrl + S) before running it?
  3. Did I type the quotes myself or copy them from somewhere?
  4. Is my important data in a file or only in variables?

Once this is clear, the next step is Variables and data types in Python: that is where you start programming for real.

Keep goingAll Fundamentals articles

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

Ready for the exam?FP1 theory mock exam — from Fundamentals to Text processing, against the clock and with your real mark (just like in the lab)