B4 - methods
import random
class Hat:
houses = ["Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"]
@classmethod
def sort(cls, name):
print(name, "is in", random.choice(cls.houses))
Hat.sort("Harry")
- the
sortmethod prints the student's assigned house - as
__init__is removed, since it need no be instantiated,clsreplacesself