Programming Fundamentals resources

Computer Science, grade 9. Notes, worksheets, videos, interactive tools and revision materials for this chapter.

Worksheets

Practice worksheet

Attempt every question before revealing the answer — that struggle is where learning happens.

1. Write a program that stores your favourite food in a variable and prints 'I love …'.
Create the variable first, then print it inside a longer string.

food = "pizza" print("I love " + food)

2. What is wrong with this code? `price = "9.99"` then `print(price + 1)`.
Check the type of price.

price is a string ("9.99"), so price + 1 tries to add a number to text — a TypeError. Fix: price = 9.99 or float(price) + 1.

3. Swap the values of a and b using a third variable temp.
Store one value safely before overwriting it.

temp = a a = b b = temp

Revision

Revision checklist

Can you explain each of these out loud, without looking? If not, re-read that lesson.

  • A variable is a named box storing one value at a time; = assigns, it doesn't mean 'equals'.
  • Core types: str (text), int (whole numbers), float (decimals), bool (True/False).
  • Names must start with a letter or underscore, and should be meaningful.
  • type() reveals a value's type; int(), float(), str() convert between types.
  • "17" (text) and 17 (number) behave differently — the type decides what operations do.

← Back to Programming Fundamentals