Let's combine everything and build a mini Pokédex — a database of Pokémon!
Inheritance lets a class inherit attributes and methods from another class:
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
print('...')
class Cat(Animal):
def speak(self):
print(f'{self.name} says Meow!')
cat = Cat('Whiskers')
cat.speak() # Whiskers says Meow!
📋 Instructions
Create a `Pokemon` class with:
- Attributes: `name`, `type`, `level`, `hp`
- Methods: `attack()`, `level_up()`, `__str__()`
Create at least 3 Pokémon and display them:
```
Pikachu (Electric) - Lv.25 - HP: 55
Charizard (Fire) - Lv.36 - HP: 78
Squirtle (Water) - Lv.10 - HP: 44
```
Get creative with the attacks and leveling up!
Create a Pokemon class with attributes: name, type, level, hp. Add methods like attack() and level_up(). Store multiple Pokemon in a list (your Pokedex)!
⚠️ Try solving it yourself first — you'll learn more!
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
print('...')
class Cat(Animal):
def speak(self):
print(f'{self.name} says Meow!')
cat = Cat('Whiskers')
cat.speak() # Whiskers says Meow!