In this problem, you will define a class to represent a competitor in a wizard battle. Your class should be named Wizard, and you should define the methods below. Hint: if you are using the print or input functions to implement these methods, you are doing it wrong. __init__: Initializes an Wizard object. Takes four parameters: the name of the wizard (a string), their age (an integer), their animal familiar’s name (a string), and their power level (an integer). These are saved in appropriate attributes. In addition, it initializes the following attributes: a Boolean value indicating if the competitor is cursed (initially False ), an integer indicating the number of potions the wizard has (initially 2). __str__: Returns a string summarizing the Wizard object, following the format below exactly: Merlin with Archimedes the Owl (205 power, 2 potions) You should use values derived from attributes in place of the bolded values. __lt__: Compares self to another Wizard object. It returns True if self is younger than the other Wizard object, and False otherwise. get_name: Returns the name of the wizard. get_power: Returns the wizard’s current power. add_potion: Increases the number of potions by one. This method has no return value. drink_potion: If the wizard has a potion, it drinks one (decrementing it from the potions counter) to increase the wizard power by 100 and remove any curse. This method has no return value. lose_power: Takes one parameter, the amount of power the wizard will lose. The wizard loses this amount of power. If this leaves the wizard with negative power, then the power is set to zero. This method has no return value. attack: The current wizard attacks a target. Takes another Wizard object as a parameter. Returns a Boolean value indicating if the attack succeeded or failed. If the current wizard is cursed or has less than 100 power, their attack fails. Otherwise, the attack succeeds: they lose 100 power and the other wizard loses 200 power.
__init__: Initializes an Wizard object. Takes four parameters: the name of the wizard (a string), their age (an integer), their animal familiar’s name (a string), and their power level (an integer). These are saved in appropriate attributes. In addition, it initializes the following attributes: a Boolean value indicating if the competitor is cursed (initially False ), an integer indicating the number of potions the wizard has (initially 2).
__str__: Returns a string summarizing the Wizard object, following the format below exactly: Merlin with Archimedes the Owl (205 power, 2 potions) You should use values derived from attributes in place of the bolded values.
__lt__: Compares self to another Wizard object. It returns True if self is younger than the other Wizard object, and False otherwise.
get_name: Returns the name of the wizard.
get_power: Returns the wizard’s current power.
add_potion: Increases the number of potions by one. This method has no return value.
drink_potion: If the wizard has a potion, it drinks one (decrementing it from the potions counter) to increase the wizard power by 100 and remove any curse. This method has no return value.
lose_power: Takes one parameter, the amount of power the wizard will lose. The wizard loses this amount of power. If this leaves the wizard with negative power, then the power is set to zero. This method has no return value.
attack: The current wizard attacks a target. Takes another Wizard object as a parameter. Returns a Boolean value indicating if the attack succeeded or failed. If the current wizard is cursed or has less than 100 power, their attack fails. Otherwise, the attack succeeds: they lose 100 power and the other wizard loses 200 power.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 7 images