Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON INHERITANCE LAB You will create a class that inherits from the following Pokemon class. class Pokemon: basic _ attack = 'tackle' damage = 4

PYTHON INHERITANCE LAB
You will create a class that inherits from the following Pokemon class.
class Pokemon:
basic_attack = 'tackle'
damage =40;
def __init__(self, name, trainer):
self.name = name
self.trainer = trainer
self.level =1
self.hp =50
self.paralyzed = False
def speak(self):
print(self.name +'!')
def attack(self, other):
if not self.paralyzed:
self.speak()
print(self.name, ' used ', self.basic_attack, '!')
other.receive_damage(self.damage)
def receive_damage(self, damage):
self.hp = max(0, self.hp - damage)
if self.hp ==0:
print(self.name, ' fainted!')
The above video lecture includes an example of a class that inherits from the Pokemon class for Electric type Pokemon. You can use this example to help you build your own Pokemon type, but be careful to follow the requirements listed below because there are some important differences.
Create a class that inherits from the Pokemon class. This class will be a type of Pokemon from this list:
Type basic_attack prob Strong Against Weak Against
Normal Body Slam .3
Ghost
Flying Bounce 3
Fighting, Bug, Grass, Fairy
Electric
Dragon Dragon Breath .3
Dark Fling 1 Ghost, Psychic Fighting, Dark, Fairy
Fighting Fling 1 Normal, Ice, Dark Bug, Dark
Ice Freeze Shock .3 Flying, Grass, Dragon Fire, Water, Ice
Ghost Lick .3
Psychic Psychic Shift 1 Fighting, Poison Bug, Ghost, Dark
Bug Signal Beam .1 Grass, Psychic, Dark Fighting, Flying, Poison, Ghost, Fire, Fairy
Fairy Sweet Kiss 1
Fighting, Dragon, Dark
Poison, Fire
Fire Blaze Kick 1 Bug, Grass, Ice Fire, Water, Dragon
Poison Poison Jab 3 Grass, Fairy Poison, Ghost
Electric Thunder Shock .1
Water Splishy Splash .3
Grass Stun Spore 1 Water Flying, Poison, Bug, Fire, Grass
Choose the Pokemon type that contains the first letter of your first, middle or last name and create a class for that pokemon that inherits from the Pokemon class. For example, if your first, middle or last name starts with the letter R, you might choose to create a class for a pokemon type that contains the letter R, like a Rock class or a Water class, which both contain the letter R. If you cannot find a pokemon type that contains the first letter of your first, middle or last name, choose Bug.
Post your class to this discussion as a .py attachment or provide a link to the github repository for your code. The .py file should import the base class and include your complete subclass code. As soon as you post your code, you will unlock all of the other posts to see the classes created by your fellow students. You will then choose one or more classes posted to the discussion by your classmates and download the code to use for Project 2.
Implementation Requirements For Your Class:
Create class named after the type of Pokemon you selected, which inherits from the Pokemon class and has the additional instance attributes, basic_attack and prob (probability).
Define __init()__ and __str()__ to take the basic_attack and probability into account. These methods are not defined in the video lecture. You will need to add them to your Pokemon type. The __init__() method must accept the hp as a parameter because it can be different for each Pokemon instance.
Define attack() for your type. Use isinstance to check the instance type. See the example in the Polymorphism section of the lecture slides lecture week 4a.pdf Download lecture week 4a.pdf
The attack method can inflict paralysis if your Pokemon type is Normal, Flying, Dragon, Dark, Fighting, Ice, Ghost, Psychic, Water, Grass or Electric. Follow the lecture video example on how to implement the paralyze feature in the attack method if you have one of these Pokemon type.
If your Pokemon type is Bug or Fairy, use the prob to inflict confusion instead. Follow the example for paralyzing an opponent, but with the message: print(other.name, 'is confused').
If your Pokemon type is Fire use the prob to inflict a burn instead. Follow the example for paralyzing an opponent, but with the message: print(other.name, 'is burned')
If your Pokemon type is Poison, use the prob to poison the opponent. Follow the example for paralyzing an opponent, but with the message: print(other.name, 'is poisoned')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

3. Identify the four characteristics of popular culture.

Answered: 1 week ago