Skip to content

Instantly share code, notes, and snippets.

@rmehta
Created January 24, 2016 16:30
Show Gist options
  • Save rmehta/89658442029a5a349523 to your computer and use it in GitHub Desktop.
Save rmehta/89658442029a5a349523 to your computer and use it in GitHub Desktop.
class House:
name = None
ability = None
students = None
class Student:
name = None
ability = None
# houses
gryffindor = House()
gryffindor.name = 'Gryffindor'
gryffindor.ability = 'bravery'
slytherin = House()
slytherin.name = 'Slytherin'
slytherin.ability = 'cunning'
# students
harry = Student()
harry.name = 'Harry Potter'
harry.ability = 'bravery'
draco = Student()
draco.name = 'Draco Malfoy'
draco.ability = 'cunning'
all_houses = [gryffindor, slytherin]
all_students = [harry, draco]
def sort(student):
for house in all_houses:
if house.ability == student.ability:
if house.students is None:
house.students = []
house.students.append(student)
print student.name + ' goes to ' + house.name + '!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment