๐งฑ L03 โ Classes Part 1 Self-Check Handout
Class: Year 9 Game On ยท 9GAMZA ยท Term 2 2026
Duration: 75 minutes (target ~50 minutes)
Marks: /75 total ยท Part A 20 ยท Part B 15 ยท Part C 20 ยท Part D 20
What we're checking: the class keyword, __init__, self, attributes (self.name), methods, creating instances. Every concept here is brand-new today โ that's expected.
Rules: Answer EVERY question to unlock Submit. Once submitted, you'll see your score + correct answers. Auto-saves on this laptop. No looking things up.
Part A โ Predict the Output
A1 (2 marks)
What prints?
class Dog:
def __init__(self, name):
self.name = name
d = Dog("Rex")
print(d.name)
A2 (2 marks)
What prints?
class Hero:
def __init__(self, hp):
self.hp = hp
h = Hero(100)
h.hp = 50
print(h.hp)
A3 (2 marks)
What prints?
class Counter:
def __init__(self):
self.value = 0
def increment(self):
self.value += 1
c = Counter()
c.increment()
c.increment()
c.increment()
print(c.value)
A4 (2 marks)
Which line will run when
Character("Arrow", 100) is created?class Character:
def __init__(self, name, hp):
self.name = name
self.hp = hp
def shout(self):
print(self.name)
A5 (2 marks)
What prints?
class Pet:
def __init__(self, name):
self.name = name
a = Pet("Cat")
b = Pet("Dog")
print(a.name, b.name)
A6 (2 marks)
What prints?
class Player:
def __init__(self, name, hp):
self.name = name
self.hp = hp
def take_damage(self, amount):
self.hp -= amount
p = Player("Aria", 100)
p.take_damage(40)
p.take_damage(20)
print(p.hp)
A7 (2 marks)
What prints?
class Box:
def __init__(self):
self.items = []
def add(self, item):
self.items.append(item)
b = Box()
b.add("sword")
b.add("potion")
print(len(b.items))
A8 (2 marks)
What prints? (Two instances do NOT share data.)
class Hero:
def __init__(self):
self.hp = 100
def heal(self, amount):
self.hp += amount
a = Hero()
b = Hero()
a.heal(50)
print(b.hp)
A9 (2 marks)
What prints?
class Hero:
def __init__(self, hp):
self.hp = hp
def is_alive(self):
return self.hp > 0
h = Hero(0)
print(h.is_alive())
A10 (2 marks)
Which TWO are correct ways to access an attribute? (Pick the option that lists exactly the correct ones.)
class Pet:
def __init__(self, name):
self.name = name
p = Pet("Rex")
# Which of these work?
# (i) p.name
# (ii) p["name"]
# (iii) Pet.name(p)
# (iv) print(p.name)
Part B โ Fill in the Blank
B1 (3 marks)
Fill in the blank โ the class definition line for a Dog class.
_________________
def __init__(self, name):
self.name = name
B2 (3 marks)
Fill in the blank โ the
__init__ signature for a Hero with name and hp parameters.class Hero:
_________________
self.name = name
self.hp = hp
B3 (3 marks)
Fill in the blank inside
__init__ to store the hp value as an attribute.class Hero:
def __init__(self, hp):
_________________
h = Hero(100)
print(h.hp) # 100
B4 (3 marks)
Fill in the blank โ a method
shout that prints "RAWR".class Dragon:
def __init__(self):
pass
_________________
print("RAWR")
B5 (3 marks)
Fill in the blank โ create an instance of
Player with name "Sam" and hp 100.class Player:
def __init__(self, name, hp):
self.name = name
self.hp = hp
_________________
print(p.name) # Sam
Part C โ Debug
C1 (5 marks)
This Dog class is missing something โ every method needs ONE special thing as its first parameter. Fix the
__init__ line.class Dog:
def __init__(name):
self.name = name
# TypeError when running Dog("Rex")
C2 (5 marks)
This Hero class doesn't actually store the hp. Fix the line inside
__init__.class Hero:
def __init__(self, hp):
hp = hp # โ does nothing useful
h = Hero(100)
print(h.hp) # AttributeError: 'Hero' object has no attribute 'hp'
C3 (5 marks)
This code prints something weird (the method object, not the result). Fix the last line.
class Hero:
def __init__(self, hp):
self.hp = hp
def is_alive(self):
return self.hp > 0
h = Hero(50)
print(h.is_alive)
# Prints: <bound method Hero.is_alive of ...>
# Should print: True
C4 (5 marks)
This
take_damage method has TWO bugs: missing self as a parameter AND wrong attribute access. Fix the def line and the body line.class Hero:
def __init__(self, hp):
self.hp = hp
def take_damage(amount): # โ bug 1
hp -= amount # โ bug 2
h = Hero(100)
h.take_damage(20)
Part D โ Coding Tasks (Write Python)
D1 (10 marks)
Task: Write a
Player class with three things: a name attribute, an hp attribute (starting at 100), and an attack(target) method that subtracts 10 from the target's hp.
Test your class with this code:
hero = Player("Aria")
goblin = Player("Goblin")
hero.attack(goblin)
hero.attack(goblin)
print(hero.name, hero.hp)
print(goblin.name, goblin.hp)
Expected output:Aria 100Goblin 80
D2 (10 marks)
Task: Write a
Pet class with: a name attribute, a hunger attribute (starts at 5), a feed() method that decreases hunger by 2 (but never below 0), and an is_hungry() method that returns True if hunger is more than 3.
Test your class with this code:
p = Pet("Rex")
print(p.is_hungry()) # True (hunger=5, more than 3)
p.feed()
print(p.is_hungry()) # False (hunger=3, NOT more than 3)
p.feed()
p.feed()
print(p.hunger) # 0 (capped, can't go below)
Expected output:TrueFalse0
Once submitted, all answers lock and you'll see your score + correct answers.
๐ Your Results
0 / 75
0%
How to submit to Google Classroom:
1. Click Copy results for Classroom โ a summary copies to your clipboard.
2. Open today's L03 assignment in Google Classroom.
3. Paste (Ctrl+V) into the comment / submission box.
4. Click Mark as done.
1. Click Copy results for Classroom โ a summary copies to your clipboard.
2. Open today's L03 assignment in Google Classroom.
3. Paste (Ctrl+V) into the comment / submission box.
4. Click Mark as done.