Full lesson content for AQA, OCR, and Edexcel specifications
Print statements let you display messages on the screen - like sending a message to the user. Every program needs to communicate with its users!
The print() function displays text on the screen. Think of it like a loudspeaker for your code.
The simplest program! Print displays text on screen.
Each print() creates a new line of output.
Text needs quotes, but numbers work without them!
Real programs use print() to give users feedback.
| Wrong | Right | Explanation |
|---|---|---|
| print(Hello) | print("Hello") | Forgot quotes around text - text always needs quotes! |
| print("Hello] | print("Hello") | Mismatched quotes - both must match |
| Print('Hi') | print('Hi') | Python is case-sensitive - must be lowercase 'print' |
| print("42") | print(42) | Numbers don't need quotes - quotes make it text! |
Comments let you add notes in your code that Python ignores - like sticky notes for programmers! Professional programmers use comments to explain what their code does.
Comments are notes in your code that Python completely ignores. They help you (and others) understand what the code does.
Comments are written with # and Python ignores them completely.
Use comments to explain what your code does - helpful when you come back later!
Comments help document what variables store - very useful in longer programs.
| Wrong | Right | Explanation |
|---|---|---|
| This is a comment | # This is a comment | Forgot the # symbol - without it, Python tries to run it as code and gives an error! |
| print("Hello") This is wrong | print("Hello") # This is right | Comments on the same line need # before them |
| /* This style doesn't work */ | # This style works in Python | Python uses # for comments, not /* */ like some other languages |
Variables are like labeled boxes that store information - you can put things in them, take things out, and use them later! They're the most fundamental building block of programming.
A variable is a named storage location. Think of it like a labeled box where you store information.
Store your name in a variable and print it.
Variables can store numbers (no quotes needed for numbers).
You can change what's stored in a variable anytime!
| Wrong | Right | Explanation |
|---|---|---|
| name = Alex | name = "Alex" | Forgot quotes around text - text needs quotes! |
| print("name") | print(name) | Quotes make it literal text, not the variable's value |
| my name = 'Jo' | my_name = 'Jo' | Variable names can't have spaces - use underscore _ |
| 123abc = 'test' | abc123 = 'test' | Variable names can't start with numbers |
Python treats numbers, text, and true/false values differently - understanding types prevents errors! Knowing data types is essential for working with user input and calculations.
Every value in Python has a type that determines what you can do with it. There are 4 main types you need to know:
Check types: Use type(value) to see what type something is!
Use type() to check what type a value is - this is super useful for debugging!
input() always gives you a string - use int() to convert to a number for math!
Use float() when you need decimal numbers for precise calculations.
Use str() to convert numbers to text so you can combine them with + for display.
| Wrong | Right | Explanation |
|---|---|---|
| age = input("Age? ") print(age + 5) |
age = int(input("Age? ")) print(age + 5) |
input() gives text! Must convert with int() before doing math |
| print("Score: " + 100) | print("Score: " + str(100)) | Can't combine text and numbers with + - use str() to convert the number first |
| number = int("3.14") | number = float("3.14") | int() can't convert decimals! Use float() for numbers with decimal points |
Python can do all the math you need - from simple addition to powerful calculations! Understanding operators is essential for games, calculators, and data analysis.
Operators are symbols that perform calculations on numbers. Python has 7 main arithmetic operators:
Order matters! Python follows BIDMAS/PEMDAS rules:
Notice the difference between / and // (Floor Division).
Multiplication happens before addition (PEMDAS/BIDMAS). Use parentheses () to force a different order.
| Wrong | Right | Explanation |
|---|---|---|
| print(10 / 2) expecting 5 | print(10 // 2) gets 5 | / always gives decimals (5.0). Use // for whole numbers (5) |
| print(5^2) | print(5**2) | Python uses ** for exponent, not ^ |
User input makes programs interactive - it's like having a conversation with your code! Every game, app, and website needs to get information from users.
The input() function asks the user a question and waits for their answer. You must store the answer in a variable to use it later.
Ask a question and store the answer in a variable.
Use + to combine the user's input with your message.
You can ask multiple questions and use all the answers!
Remember: input() gives you text! Convert to numbers with int() or float().
| Wrong | Right | Explanation |
|---|---|---|
| input("What's your name?") | name = input("What's your name?") | Must store the answer in a variable! |
| age = input("Age? ") print(age + 5) |
age = int(input("Age? ")) print(age + 5) |
input() gives text! Use int() to convert for math |
| print("Hello " + input()) | name = input("Name? ") print("Hello " + name) |
Store input in a variable first for clearer code |
String concatenation lets you join pieces of text together - like building sentences from smaller parts! It's how programs create personalized messages.
Concatenation means joining strings together. Think of it like linking train carriages - you connect them end-to-end!
The + operator joins two strings into one.
Output: HelloWorld
Don't forget spaces! "Hello " + "World" is different from "Hello" + "World"
Output:
Hello World
Python is awesome!
You can join variables and strings together.
Output: Alex Smith
Real programs use concatenation to create personalized output.
Output:
Player: Sam
Now playing: Python Quest
| Wrong | Right | Explanation |
|---|---|---|
| print("Score: " + 100) | print("Score: " + str(100)) | Can't join strings and numbers! Use str() to convert |
| print("Hello"+"World") | print("Hello " + "World") | Forgot space between words! Add " " or space in string |
| name = "Jo" print("Hello name") |
name = "Jo" print("Hello " + name) |
Quotes make it literal text! Use + to add the variable |
String methods are like tools that let you transform and manipulate text - make it LOUD, quiet, or measure it! They're essential for processing user input and formatting text.
Methods are special functions that belong to strings. You call them by putting a dot after a string.
The .upper() method converts all letters to uppercase.
Output: HELLO
The .lower() method converts all letters to lowercase.
Output: python
len() tells you how many characters are in a string (including spaces!).
Output: 11
Methods are perfect for cleaning up user input and making comparisons case-insensitive.
| Wrong | Right | Explanation |
|---|---|---|
| text.upper | text.upper() | Forgot the parentheses! Methods need () to work |
| text = "hi" text.upper() print(text) |
text = "hi" text = text.upper() print(text) |
Methods don't change the original! Store the result |
| text.len() | len(text) | len() is not a method! It goes before the string |
Strings are like lists of characters you can slice, dice, and manipulate! This is essential for processing data, extracting information, and text manipulation.
Every character in a string has a position (index). Python counts from 0!
Use square brackets [] with an index number to get a specific character.
Output:
P
n
Use [start:stop] to get a section. The stop position is NOT included!
Output:
Hello
World
Use .split() to break text into separate words (creates a list).
Output:
['Hello', 'my', 'name', 'is', 'Alex']
Hello
Use .replace(old, new) to swap text.
Output: Hello Python
Real programs combine multiple string operations.
Output:
Username: user
Domain: example.com
| Wrong | Right | Explanation |
|---|---|---|
| word = "Hi" print(word[2]) |
word = "Hi" print(word[1]) |
Index out of range! "Hi" has indices 0 and 1 only |
| text[0:5] includes index 5 | text[0:5] goes up to but NOT including index 5 | Stop index is exclusive - not included in result |
| words = text.split print(words) |
words = text.split() print(words) |
Forgot parentheses! Methods need () to execute |
If statements let your program make decisions - like choosing different paths based on conditions! This is how programs become intelligent and responsive.
If statements check whether something is true or false, then execute code accordingly.
Check a condition and run code only if it's true.
Output: You can create a social media account
Different ways to compare values.
Output:
Great job!
You scored some points
Use else to handle when the condition is false.
Output: Keep trying!
Use elif to check multiple conditions in order. Python stops at the first true condition!
Output: Nice weather
Use and when BOTH conditions must be true. Use or when at least ONE must be true.
Output:
You can watch the movie
Enjoy the show!
| Wrong | Right | Explanation |
|---|---|---|
| if age > 12 print("Old enough") |
if age > 12: print("Old enough") |
Forgot colon (:) and indentation! |
| if age = 18: | if age == 18: | Use == for comparison, = is for assignment! |
| if age > 12 and < 18: | if age > 12 and age < 18: | Must repeat the variable in compound conditions |
| if age >= 18: print("Adult") print("More") |
if age >= 18: print("Adult") print("More") |
All code in the if block must be indented the same amount |
Programs often need to choose between MORE than two options - like grades A, B, C, D, or F! Elif and else let you handle multiple paths elegantly.
Elif (short for "else if") lets you check multiple conditions in sequence. Python checks them in order and stops at the first true one.
Check conditions in order - Python stops at the first match!
Output: Grade: C
Handle multiple age ranges with elif.
Output: Teenager
Real programs use elif for menu choices.
| Wrong | Right | Explanation |
|---|---|---|
| if score >= 70: if score >= 60: |
if score >= 70: elif score >= 60: |
Use elif, not multiple ifs! Multiple ifs check ALL conditions |
| if age > 18: else age > 13: |
if age > 18: elif age > 13: |
else doesn't take a condition! Use elif for more conditions |
| elif score >= 90: if score >= 80: |
if score >= 90: elif score >= 80: |
Must start with if! Can't begin with elif |
Real programs need to check multiple conditions at once - like "if age > 18 AND has_license"! Boolean logic powers every decision in games, apps, and websites.
Boolean logic lets you combine multiple True/False conditions using three special operators:
Both conditions must be True for the code to run.
Output: You can drive!
Only ONE condition needs to be True for the code to run.
Output: Sleep in!
The not operator flips True to False and False to True.
Output: Go outside!
You can combine and, or, and not in complex conditions.
Output: Access granted
| Wrong | Right | Explanation |
|---|---|---|
| if age > 18 && has_license: | if age > 18 and has_license: | Python uses 'and', not && like other languages |
| if age > 18 || age < 65: | if age > 18 or age < 65: | Python uses 'or', not || like other languages |
| if age > 18 and < 65: | if age > 18 and age < 65: | Must repeat the variable in each condition |
For loops let you repeat code a specific number of times - perfect for counting, processing lists, or repeating tasks! When you know HOW MANY times to repeat, use a for loop!
For loops repeat code for each item in a sequence.
The simplest for loop - i will be 0, 1, 2, 3, 4 automatically!
Output:
0
1
2
3
4
Use for loops to repeat the same action multiple times.
Output:
Hello!
Hello!
Hello!
Use range(start, stop) to count from a specific number.
Output:
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
For loops can iterate through every item in a list.
Output:
Hello, Alex
Hello, Sam
Hello, Jo
Use for loops to process data and accumulate results.
Output:
Total: 350
Average: 87.5
| Wrong | Right | Explanation |
|---|---|---|
| for i in range(5) print(i) |
for i in range(5): print(i) |
Forgot colon (:) and indentation! |
| for i in range(1, 5): # Expecting 1,2,3,4,5 |
for i in range(1, 6): # Gets 1,2,3,4,5 |
range() stops BEFORE the end number (5 is not included!) |
| for i in range(5): total = 0 total = total + i |
total = 0 for i in range(5): total = total + i |
Initialize variables BEFORE the loop, not inside! |
While loops let your code repeat actions automatically - like counting, checking, or waiting until something happens! Use while loops when you DON'T know exactly how many times to repeat.
While loops repeat code over and over as long as a condition is true. Think of them like saying "keep doing this WHILE something is true."
A simple while loop that counts from 1 to 5.
Output:
1
2
3
4
5
Count down from 5 to 1, then blast off!
Output:
5
4
3
2
1
Blast off!
Keep asking the user until they type "stop".
Output (if user enters 'go' then 'stop'):
Type 'stop' to exit: go
Type 'stop' to exit: stop
Loop finished!
Loop until the user guesses correctly.
| Wrong | Right | Explanation |
|---|---|---|
| count = 1 while count <= 5: print(count) |
count = 1 while count <= 5: print(count) count = count + 1 |
Forgot to update the variable! Creates infinite loop |
| while count = 5: | while count == 5: | Use == for comparison, not = (which is assignment) |
| while True: print("Hi") |
while True: answer = input() if answer == "stop": break |
Infinite loop! Need a way to exit (use break or change condition) |
Lists let you store multiple values in one variable - like a shopping list, a to-do list, or a collection of scores! Instead of making 10 variables, make 1 list!
Lists are containers that hold multiple values in order. Each item has a position (index).
Create a list with square brackets and commas between items.
Output:
['Alex', 'Sam', 'Jo']
[85, 92, 78, 95]
IMPORTANT: Python starts counting at 0, not 1!
Output:
Alex
Sam
Jo
Use len() to find out how many items are in a list.
Output: Total names: 4
Use .append() to add items to the end of a list.
Output:
Total tasks: 3
First task: homework
['homework', 'practice', 'read']
Combine lists with for loops to process every item.
Output:
Score: 85
Score: 92
Score: 78
Score: 95
| Wrong | Right | Explanation |
|---|---|---|
| names = ['Alex', 'Sam', 'Jo'] print(names[3]) |
names = ['Alex', 'Sam', 'Jo'] print(names[2]) |
Index out of range! List has indices 0, 1, 2 only |
| names = ['Alex', 'Sam'] print(names[1]) # Expecting 'Alex' |
names = ['Alex', 'Sam'] print(names[0]) # Gets 'Alex' |
Lists start at index 0, not 1! |
| scores.append(85, 92) | scores.append(85) scores.append(92) |
.append() adds ONE item at a time |
Games, spreadsheets, and maps all use grids - 2D lists let you store data in rows and columns! Essential for tic-tac-toe, battleship, seating charts, and image processing.
A 2D list is a list of lists - like a table with rows and columns.
Create a grid by making a list of lists.
Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Use [row][column] with TWO separate brackets!
Output:
1
3
5
7
Update a specific position in the grid.
Output: ['.', 'O', '.']
Use nested for loops to access every item in a 2D list.
Output:
1 2 3
4 5 6
2D lists are perfect for game boards!
Output:
['X', 'O', 'X']
['O', 'X', 'O']
['.', '.', 'X']
| Wrong | Right | Explanation |
|---|---|---|
| grid[0, 1] | grid[0][1] | Need TWO separate brackets [row][column], not one! |
| grid[1][3] # 3 columns only |
grid[1][2] # Valid access |
Index out of range! Columns are 0, 1, 2 |
| grid[column][row] | grid[row][column] | Wrong order! Row comes first, then column |
Don't Repeat Yourself! Functions let you write code once and use it many times! Real programmers use functions for EVERYTHING - they make code organized, readable, and maintainable.
A function is a named, reusable block of code that performs a specific task. They make code organized, easier to read, and simpler to debug.
Create a simple function and call it multiple times.
Output:
Hello!
Hello!
Write the code once, use it many times!
Output:
Welcome to Python Coach!
Let's learn together!
Simple functions that do the same thing every time.
Output:
1. Start Game
2. Load Game
3. Quit
| Wrong | Right | Explanation |
|---|---|---|
| def greet() print("Hi") |
def greet(): print("Hi") |
Forgot colon (:) and indentation! |
| def greet(): print("Hi") greet |
def greet(): print("Hi") greet() |
Forgot parentheses ()! Need them to call the function |
| Def greet(): | def greet(): | Python is case-sensitive! Must be lowercase 'def' |
Parameters let functions receive information, and return lets functions give back results! This makes functions incredibly powerful and flexible.
Parameters are variables listed inside the parentheses in the function definition. They let the function receive information when it's called.
Parameters make functions flexible - they can work with different data!
Output:
Hello, Alex!
Hello, Sam!
Functions can accept multiple pieces of information.
Output:
Area: 50
Area: 21
The return keyword sends a value back to the code that called the function.
Output:
12
52
Return gives data back, print just displays it. Return is more powerful!
Output:
Total: 8
Double: 16
Combine parameters and return for powerful, reusable code.
Output:
Grade 1: A
Grade 2: C
| Wrong | Right | Explanation |
|---|---|---|
| def greet(name): print("Hi " + name) greet() |
def greet(name): print("Hi " + name) greet("Alex") |
Function expects a parameter! Must provide an argument |
| def add(a, b): return a + b add(5, 3) |
def add(a, b): return a + b result = add(5, 3) print(result) |
Return value is lost! Must store it in a variable or use it |
| def add(a, b): print(a + b) total = add(5, 3) |
def add(a, b): return a + b total = add(5, 3) |
print doesn't return! Use return to get values back |
File writing is crucial for saving settings, recording high scores, logging program activity, or creating output reports. It lets your program persistently store information!
To write data, you must open the file in the correct mode:
Write mode creates a new file or completely replaces existing content.
Warning: If run again, the previous content is erased!
Append mode adds content to the end without erasing existing data.
Note: Each time this runs, a new entry is ADDED to the end.
Remember to add \n for each new line!
Real programs save user input to files.
| Wrong | Right | Explanation |
|---|---|---|
| file.write("Line 1") file.write("Line 2") |
file.write("Line 1\n") file.write("Line 2\n") |
Forgot \n! Lines will run together without newlines |
| with open("data.txt") as file: | with open("data.txt", "w") as file: | Must specify "w" or "a" mode for writing! |
| with open("scores.txt", "w") as file: file.write("Score 1\n") # Run again - Score 1 lost! |
with open("scores.txt", "a") as file: file.write("Score 1\n") # Run again - Score 1 kept! |
Using "w" when you meant "a" - erases existing data! |
Store information with labels! Like a real dictionary: look up a word (key) to get its meaning (value). Perfect for storing user profiles, game stats, and settings.
A dictionary is a collection of key-value pairs. Keys must be unique (like words in a dictionary), and they point to a value (the definition).
Create a dictionary with curly braces and key:value pairs.
Output: {'name': 'Sam', 'age': 16, 'score': 95}
Access values using the key in square brackets.
Output:
Name: Sam
Age: 16
Add new data by assigning to a new key.
Output: {'name': 'Sam', 'age': 16, 'city': 'New York', 'score': 95}
Update existing values by reassigning to the key.
Output: New score: 100
Loop through all key-value pairs using .items() method.
Output:
name is Sam
age is 16
score is 95
| Wrong | Right | Explanation |
|---|---|---|
| user = {'name' 'Sam'} | user = {'name': 'Sam'} | Forgot the colon (:) between key and value! |
| user = {name: 'Sam'} | user = {'name': 'Sam'} | Keys must be in quotes (strings)! |
| print(user.name) | print(user['name']) | Use square brackets [], not dot notation! |
| print(user['city']) # Key doesn't exist |
user['city'] = 'London' print(user['city']) |
KeyError! Must add the key before accessing it |
How do you find something in a list? Check each item, one by one, until you find it! This is called Linear Search - the most fundamental searching algorithm.
Linear search is an algorithm that finds a target value by checking every single item in a list sequentially, from the first item to the last.
Use a for loop with range(len(list)) to get the indices.
Output: Found at index: 2
Wrap the search logic in a function that returns the index, or -1 if not found.
Call the function and check if the item was found.
Output: Mango is at index 3
Linear search works with any data type!
Output: Score 95 found at position 3
Understand how linear search works by counting comparisons.
Output: Found after 5 comparisons
| Wrong | Right | Explanation |
|---|---|---|
| for item in data_list: if item == target: return item |
for i in range(len(data_list)): if data_list[i] == target: return i |
Need to return the INDEX, not the item itself! |
| def search(list, target): for i in range(len(list)): if list[i] == target: return i |
def search(data_list, target): for i in range(len(data_list)): if data_list[i] == target: return i return -1 |
Forgot to return -1 when not found! Also, don't name variables 'list' |
| return i return -1 |
return i return -1 |
return -1 must be OUTSIDE the loop (not indented)! |
Stop your programs from crashing! Handle errors gracefully and keep your code running smoothly. Professional programs don't crash - they handle errors intelligently.
Python provides the try...except structure to manage errors (exceptions) that could cause the program to stop.
The int(input()) conversion causes a ValueError if the user types letters.
Output (if user enters 'hello'):
Error: Please enter only numbers!
Catch specific errors to provide better error messages.
Combine try/except with a while loop to force valid input.
Handle errors when working with files that might not exist.
Complete example combining multiple error types.
| Wrong | Right | Explanation |
|---|---|---|
| try x = int(input()) |
try: x = int(input()) |
Forgot the colon (:) after try! |
| try: x = int(input()) print("Done") |
try: x = int(input()) except: print("Error") |
try must have a matching except block! |
| while True: age = int(input()) break |
while True: try: age = int(input()) break except: print("Error") |
No error handling! Will crash on invalid input |
Real programs need to load data from files - user settings, game saves, and datasets! File reading lets your programs persist data and work with external information.
You need to open a file, read its content, and then close it.
Use .read() to get all content as one string.
Output: Hello from the file!
The with statement automatically closes the file - best practice!
Use .readlines() to get a list of all lines. Use .strip() to remove newline characters.
Output (for a file with two lines):
First line.
Second line.
Read a file and process each line.
Combine file reading with try/except for robust code.
| Wrong | Right | Explanation |
|---|---|---|
| file = open("data.txt", "r") content = file.read() |
with open("data.txt", "r") as file: content = file.read() |
Use 'with' to automatically close the file! |
| with open("data.txt") as file: | with open("data.txt", "r") as file: | Should specify "r" mode for clarity (though it's default) |
| lines = file.readlines() for line in lines: print(line) |
lines = file.readlines() for line in lines: print(line.strip()) |
Forgot .strip()! Each line has \n at the end |
Imagine bubbles rising in water - the biggest ones float to the top first! That's exactly how bubble sort works with numbers. Bubble sort is the simplest sorting algorithm - perfect for learning how sorting works!
Bubble sort repeatedly compares adjacent pairs of items and swaps them if they are in the wrong order. Each pass moves the next largest item to its final position at the end of the list (like a bubble rising).
Python makes swapping easy with simultaneous assignment.
Output: [2, 5, 8, 1]
The complete bubble sort algorithm with nested loops.
Output: [12, 22, 25, 34, 64]
See how bubble sort works by printing after each pass.
Output:
Pass 1
[2, 5, 1, 8, 9]
Pass 2
[2, 1, 5, 8, 9]
Pass 3
[1, 2, 5, 8, 9]
Pass 4
[1, 2, 5, 8, 9]
Final sorted: [1, 2, 5, 8, 9]
Wrap bubble sort in a reusable function.
Output: [78, 85, 88, 92, 95]
Change the comparison operator to sort in descending order.
Output: [9, 8, 5, 2, 1]
| Wrong | Right | Explanation |
|---|---|---|
| for j in range(len(numbers)): | for j in range(len(numbers) - 1): | Index out of range! Need -1 because accessing j+1 |
| temp = numbers[j] numbers[j] = numbers[j+1] numbers[j+1] = temp |
numbers[j], numbers[j+1] = numbers[j+1], numbers[j] | Python's swap is much simpler! No temp variable needed |
| for i in range(len(numbers)): for j in range(len(numbers)): |
for i in range(len(numbers) - 1): for j in range(len(numbers) - 1 - i): |
Need -1 in both loops! Also optimize with -i |
Merge sort is used because simple sorts like bubble sort are SLOW. For 1000 items, bubble sort is ~50 times slower than merge sort. Merge sort uses divide and conquer - it's how Python's built-in sort() works!
The core idea is Divide, Conquer, and Combine.
Split the list into two halves using the middle index.
Output:
Original: [38, 27, 43, 3, 9, 82, 10]
Left half: [38, 27, 43]
Right half: [3, 9, 82, 10]
Merge two sorted lists into one sorted list.
Output: [3, 9, 10, 27, 38, 82]
The full recursive merge sort algorithm.
Output: [3, 9, 10, 27, 38, 43, 82]
See the divide and conquer process in action.
| Wrong | Right | Explanation |
|---|---|---|
| if len(items) == 1: | if len(items) <= 1: | Need <= to handle empty lists! Base case includes 0 and 1 |
| merge_sort(items) # Original unchanged |
items = merge_sort(items) print(items) |
merge_sort returns a new list! Must capture the result |
| middle = len(items) / 2 | middle = len(items) // 2 | Need integer division //! Regular / gives float |
Stacks and queues are fundamental data structures used everywhere in computing - from browser history (stack) to printer queues (queue)! Understanding these structures is essential for GCSE Computer Science.
A stack is a Last In, First Out (LIFO) data structure - like a stack of plates! The last plate you put on top is the first one you take off.
Implement a stack using Python lists.
Output:
Stack: ['Page 1', 'Page 2', 'Page 3']
Top: Page 3
Removed: Page 3
Stack: ['Page 1', 'Page 2']
A queue is a First In, First Out (FIFO) data structure - like a queue of people! The first person in line is the first person served.
Implement a queue using Python lists.
Output:
Queue: ['Customer 1', 'Customer 2', 'Customer 3']
Front: Customer 1
Served: Customer 1
Queue: ['Customer 2', 'Customer 3']
Real-world example: implementing browser back button.
Output:
Visiting: google.com
Visiting: youtube.com
Visiting: github.com
Back to: youtube.com
Back to: google.com
Real-world example: managing a printer queue.
Output:
Added: Document 1
Added: Document 2
Added: Document 3
Printing: Document 1
Printing: Document 2
Remaining: ['Document 3']
| Wrong | Right | Explanation |
|---|---|---|
| stack.pop(0) # For stack |
stack.pop() # For stack |
Stack removes from END! .pop() not .pop(0) |
| queue.pop() # For queue |
queue.pop(0) # For queue |
Queue removes from FRONT! .pop(0) not .pop() |
| if stack: # Check empty |
if len(stack) > 0: # Check empty |
Be explicit! Use len() for clarity |
Every app and website needs to verify who's using it. Authentication means proving you are who you say you are (your identity). It's fundamental to modern computing security!
The core process is to Verify Identity using a Username + Password. Authorization is a different step that determines what you can do after logging in (your permissions).
Store users in a dictionary with username as key and password as value.
Output: Registered users: ['alice', 'bob', 'charlie']
Check if username exists and password matches.
Let users create new accounts with validation.
Combine registration and login with validation.
⚠️ Important Security Notes:
Check that passwords meet security requirements.
| Wrong | Right | Explanation |
|---|---|---|
| users = {'alice', 'bob'} | users = {'alice': 'pass1', 'bob': 'pass2'} | Need key:value pairs! Can't just store usernames |
| if password == users[username]: | if username in users: if password == users[username]: |
Check username exists first! Otherwise KeyError |
| users[username] = password # No validation |
if len(password) >= 8: users[username] = password |
Always validate password strength! |
📚 Complete Coverage: Lessons 1-27
This document contains full teaching content for all 27 lessons including: Input Function • String Operations • Selection Statements • Loops • Lists & 2D Lists • Functions • File Handling • Dictionaries • Algorithms (Linear Search, Bubble Sort, Merge Sort) • Error Handling • Stacks & Queues • Authentication
Use Ctrl+F to search for any topic across the complete curriculum
Python Coach - Complete GCSE Curriculum Reference
27 Comprehensive Lessons • 100% Specification Coverage
AQA 8525 | OCR J277 | Edexcel 1CP2