Skip to content

Instantly share code, notes, and snippets.

@vu3jej
Created March 3, 2015 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vu3jej/8c3107cfdda786a8a798 to your computer and use it in GitHub Desktop.
Save vu3jej/8c3107cfdda786a8a798 to your computer and use it in GitHub Desktop.
Snippet from week 6 of MITx: 6.00.1x Introduction to Computer Science and Programming Using Python
class Spell(object):
def __init__(self, incantation, name):
self.name = name
self.incantation = incantation
def __str__(self):
return self.name + ' ' + self.incantation + '\n' + self.getDescription()
def getDescription(self):
return 'No description'
def execute(self):
print self.incantation
class Accio(Spell):
def __init__(self):
Spell.__init__(self, 'Accio', 'Summoning Charm')
class Confundo(Spell):
def __init__(self):
Spell.__init__(self, 'Confundo', 'Confundus Charm')
def getDescription(self):
return 'Causes the victim to become confused and befuddled.'
def studySpell(spell):
print spell
spell = Accio()
spell.execute()
studySpell(spell)
studySpell(Confundo())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment