Lesson 1 · Programming

🐍 Python: Variables, Input & Decisions

Python powers websites, science and games. Just a few lines can already make a program that talks back.

📦 Variables and input

A variable stores a value. input() always returns a string, so use int() or float() to change its type (this is casting). print() shows output.

name = input("Your name? ") age = int(input("Your age? ")) print("Hi", name) print("Next year:", age + 1)

🔀 Selection

if, elif and else choose what runs. Python uses indentation to mark the blocks. Use == to compare and = to assign.

mark = 72 if mark >= 80: print("A") elif mark >= 60: print("B") else: print("C") # prints B
Try it: type these into any free online Python editor and change the numbers.
✏️ Quick check · 1 of 6
Input

In Python, input() returns:

Text, always.
✏️ Quick check · 2 of 6
Cast

To turn "7" into a whole number, use:

Integer.
✏️ Quick check · 3 of 6
Compare

Which tests whether x equals 5?

Two equals signs.
✏️ Quick check · 4 of 6
Blocks

Python marks a block of code with:

Spaces at the start.
✍️ Type your answer · 5 of 6

x = 4 y = x * 3 + 1

What is the value of y?

Enter an exact answer, without rounding.
Multiply first.
✍️ Type your answer · 6 of 6

print(17 % 5)

What does this print?

Enter an exact answer, without rounding.
The remainder.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5

print(2 ** 3) outputs:

Question 2 of 5

print(7 // 2) outputs:

Question 3 of 5

What is the type of 3.5?

Question 4 of 5

Which is a valid variable name?

Question 5 of 5

If mark = 60, the program above prints:

Lesson 2 · Programming

🔁 Python: Loops, Lists & Functions

Computers never get bored. Loops repeat work, lists hold data and functions let you reuse your best ideas.

🔁 Loops and lists

A for loop repeats a set number of times; a while loop repeats while a condition is true. A list stores many values, and its first index is 0.

for i in range(3): print(i) # 0 1 2 scores = [5, 8, 2] scores.append(9) print(scores[0]) # 5 print(len(scores)) # 4

🧰 Functions

A function is a named block of code. def defines it, parameters receive values and return sends a result back. A local variable exists only inside its function.

def area(w, h): return w * h print(area(3, 4)) # 12 total = 0 for n in [2, 4, 6]: total = total + n print(total) # 12
✏️ Quick check · 1 of 6
Range

range(3) gives the numbers:

Starts at 0.
✏️ Quick check · 2 of 6
While

A while loop keeps going:

Check the condition.
✏️ Quick check · 3 of 6
Define

Which word defines a function?

Short for define.
✍️ Type your answer · 4 of 6

nums = [4, 7, 9]

What is nums[1]?

Enter an exact answer, without rounding.
Count from 0.
✍️ Type your answer · 5 of 6

nums = [4, 7, 9] nums.append(1)

What is len(nums)?

Enter an exact answer, without rounding.
Count the items.
✍️ Type your answer · 6 of 6

total = 0 for i in range(1, 5): total = total + i

What is total after the loop?

Enter an exact answer, without rounding.
range stops before 5.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5

The first item of a list is at index:

Question 2 of 5

return in a function:

Question 3 of 5

A loop that never ends is called:

Question 4 of 5

def double(x): return x * 2. double(5) gives:

Question 5 of 5

A local variable can be used:

Lesson 3 · Problem solving

📝 Pseudocode, Validation & Testing

Before coding, plan. After coding, try to break it. That is how reliable software gets made.

📝 Pseudocode and trace tables

Pseudocode sets out an algorithm in structured English, independent of any language. A trace table records each variable’s value at each step.

Total ← 0 FOR Count ← 1 TO 3 INPUT Number Total ← Total + Number NEXT Count OUTPUT Total inputs 2, 5, 3: Total goes 2, 7, 10

🛡️ Validation, verification and testing

Validation checks that data is sensible: range, length, type, presence, format and check digit. Verification checks that data was entered correctly: double entry or a visual check. Test with normal, abnormal, extreme and boundary data.

Age must be 13 to 19 normal: 15 abnormal: 40, or "ten" extreme: 13 and 19 boundary: 12 and 13, or 19 and 20
Validation cannot prove data is true. An age of 15 passes the check, even if the person is really 16.
✏️ Quick check · 1 of 6
Pseudocode

Pseudocode is:

For people to read.
✏️ Quick check · 2 of 6
Validation

A range check tests whether a value:

A minimum and a maximum.
✏️ Quick check · 3 of 6
Verification

Double entry of a password is:

Compares two entries.
✏️ Quick check · 4 of 6
Test data

For a valid range of 13 to 19, 40 is:

Far outside the range.
✍️ Type your answer · 5 of 6

Total ← 0. FOR Count ← 1 TO 4, Total ← Total + Count. NEXT Count.

What is Total at the end?

Enter an exact answer, without rounding.
Trace each pass.
✍️ Type your answer · 6 of 6

A valid range is 13 to 19.

What is the largest extreme value that should be accepted?

Enter an exact answer, without rounding.
The very edge of the valid range.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5

Which check makes sure a field is not left empty?

Question 2 of 5

A check digit is mainly used to detect:

Question 3 of 5

A trace table is used to:

Question 4 of 5

Boundary data tests values:

Question 5 of 5

← in Cambridge-style pseudocode means:

Final Challenge

🏆 6-Question Challenge Quiz

Questions from every topic in this course. Pick an answer for each one, then hit Check My Answers.

0 / 6
💪 Keep practicing — go back through the lessons and retake the quiz!
Q1 · Python: Variables, Input & Decisions

A # in Python starts a:

Q2 · Python: Variables, Input & Decisions

int(input()) is an example of:

Q3 · Python: Loops, Lists & Functions

scores[2] gets which item?

Q4 · Python: Loops, Lists & Functions

Which adds an item to the end of a list?

Q5 · Pseudocode, Validation & Testing

A type check tests whether data:

Q6 · Pseudocode, Validation & Testing

Validation shows that data is: