In this worksheet, you will review the most important Python basics from L1 to L12. First, you will revise key ideas and study examples that show how to write correct code. Then, you will complete short individual tasks to practise each skill. Finally, you and your partner will work together on three pair challenges, where you will combine skills to build mini-programs.
The goal is to practise writing correct code, fixing syntax mistakes, and thinking carefully about logic. Check your confidence at the end to see which areas you feel strong in and which you need to improve.
Online resources to help you (in addition to the pages in this course):
Learn how to use print(), handle basic data types (str, int, float), collect user input with input(), and save information in variables using =.
L1 Print:
Use print("text") to show messages on the screen. Always use speech marks " " around text.
L2 Data Types:
Understand str (text), int (whole numbers), and float (decimals) to manage different kinds of data.
L3 Input:
Use input("question") to collect user input.
Important: Save the input using = if you want to use it later.
L4 Variables:
Variables store data.
Example: name = "Alex" — lowercase variable names are best practice.
Learn to use operators (+, -, *, /, ==, !=) to perform calculations and comparisons, and control the flow of the program using conditionals (if, elif, else).
L5 Operators:
Operators do actions:
+ add
- subtract
* multiply
/ divide
== check if equal
!= check if not equal
Remember: = saves a value into a variable, == compares two values.
L6 Conditionals:
Use if, elif, and else to make decisions based on conditions.
Always end condition lines with a : and indent properly.
Use for loops to repeat code multiple times and control how your loop counts using range(), including start, stop, and step values.
for i in range(x): repeats from 0 up to (but not including) x.
range(1,10) starts at 1 and ends at 9.
range(1,10,2) counts by 2s: 1, 3, 5, 7, 9.
Functions (def) let you create blocks of reusable code. You can pass parameters inside the parentheses and return results using return.
Create a function with def function_name(parameters):.
Inside the function, use return to send back a result.
Example:
def greet(name):
return "Hello, " + name
Lists and dictionaries are ways to store groups of data. Use for item in list to loop through a list, .append() to add to lists, .get() to retrieve dictionary values, and [key] to modify them.
L9 Lists:
Store many items inside square brackets [ ].
Example: ["apple", "banana", "cherry"]
Loop through a list with for item in list_name:.
Add items with .append(item).
L10 Dictionaries:
Store key-value pairs inside {}.
Example: {"name": "Alex", "age": 14}
Access values safely with .get("key").
Modify values with dict["key"] = new_value.
Use try: and except: to catch problems like wrong input, especially catching specific errors like ValueError when converting input to numbers.
Surround riskier code with try - for example catching errors from incorrect user input.
Catch mistakes using except: or except ValueError: to handle specific errors.
Example:
try:
num = int(input("Enter a number: "))
except ValueError:
print("That's not a number!")
Classes let you group variables (attributes) and methods (functions inside a class) together. Use class ClassName:, define variables inside __init__(), and access them using self..
Create a class using class ClassName:.
Set up the object's variables with __init__(self, ...).
Example:
class Dog:
def __init__(self, name):
self.name = name
Look at the output comments to understand what your program should do.
Printing and Variables (L1–L4)
name = input("What is your name?")
print("Hello, " + name)
# Example input: Alex
# Output: Hello, Alex
Operators and Conditionals (L5–L6)
a = int(input("First number: "))
b = int(input("Second number: "))
if a + b > 10:
print("Big total!")
else:
print("Small total!")
# Example input: 7 and 6
# Output: Big total!
Loops (L7)
for i in range(1, 10, 2):
print(i)
# Output:
# 1
# 3
# 5
# 7
# 9
Functions (L8)
def greet(name):
return "Welcome, " + name
print(greet("Alex"))
# Output: Welcome, Alex
Lists and Dictionaries (L9–L10)
items = ["pen", "pencil", "eraser"]
for item in items:
print(item)
# Output:
# pen
# pencil
# eraser
student = {"name": "Alex", "age": 14}
print(student.get("name"))
# Output: Alex
student["age"] = 15
print(student["age"])
# Output: 15
Error Handling (L11)
try:
age = int(input("Enter your age: "))
except ValueError:
print("That’s not a number!")
# Example input: abc
# Output: That’s not a number!
OOP (L12)
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return self.name + " says woof!"
dog1 = Dog("Buddy")
print(dog1.bark())
# Output: Buddy says woof!
✅ Print your favorite color.
✅ Ask the user for their name and age. Save the answers.
✅ Add two numbers and check if the result is greater than 20.
✅ Print every number from 1 to 10 using a loop.
✅ Write a function that returns double the number given.
✅ Make a list of three animals. Add another one.
✅ Make a dictionary with your name and hobby. Print your hobby.
✅ Handle an input error when asking for a number.
Work together. Share the keyboard fairly. Complete all 3 challenges.
Challenge 1: Mini Program (L1–L7)
Ask the user's name and favorite number.
If the number is above 5, print a special greeting.
Loop and print the user's name 3 times.
Use a function to print "Goodbye, (name)".
Challenge 2: Inventory Manager (L1–L9)
Make a list of 3 objects (input from user).
Print each item nicely.
Add a 4th item from user input.
Make a dictionary that includes "owner": name, and "items": list.
Print out the dictionary nicely.
Challenge 3: Pet Creator (L1–L12)
Create a class Pet with name and type (dog, cat, etc.).
Include a method describe() that says: "(name) is a (type)."
Ask the user to create two pets.
Print the description of each pet using the method.
Handle wrong inputs if the user types a number instead of text.