Question: class Spell: def __init__(self, name, incantation): self.name = name self.incantation = incantation def __str__(self): return self.name + + self.incantation + +

class Spell: def __init__(self, name, incantation): self.name = name self.incantation = incantation def __str__(self): return self.name + " " + self.incantation + " " + self.get_description() def get_description(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 get_description(self): return "Causes the victim to become confused and befuddled" def study_spell(spell): print(spell) # test spell = Accio() spell.execute() study_spell(spell) study_spell(Confundo())

Based on the Python code given above, answer the following questions:

  1. a) Which are the parent and child classes here?

  2. b) What is the output of the code? (Try figuring it out without running it)

  3. c) Which get_description() method is called when the study spell(Confundo()) function

    is executed? Why?

  4. d) What do we need to do so that that statement print(Accio()) will print the

    description This charm summons an object to the caster, potentially over a significant distance? Write down the code that needs to be added or changed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!