Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
-
a) Which are the parent and child classes here?
-
b) What is the output of the code? (Try figuring it out without running it)
-
c) Which get_description() method is called when the study spell(Confundo()) function
is executed? Why?
-
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started