We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Superhero: def init(self, name, power, weakness): self.name = name self.power = power self.weakness = weakness
def display_info(self): print(f"Name: {self.name}") print(f"Power: {self.power}") print(f"Weakness: {self.weakness}") def action(self): print(f"{self.name} is using their superpower: {self.power}!")
class FlyingHero(Superhero): def init(self, name, power, weakness, flight_speed): super().init(name, power, weakness) self.flight_speed = flight_speed
def action(self): print(f"{self.name} is flying at speed of {self.flight_speed}!")
class StrengthHero(Superhero): def init(self, name, power, weakness, strength_level): super().init(name, power, weakness) self.strength_level = strength_level
def action(self): print(f"{self.name} is showing their strength level of {self.strength_level}!")
class Animal: def move(self): print("Animal is moving")
class Dog(Animal): def move(self): print("Dog is running 🐕")
class Bird(Animal): def move(self): print("Bird is flying 🕊️")
class Vehicle: def move(self): print("Vehicle is moving")
class Car(Vehicle): def move(self): print("Car is driving 🚗")
class Plane(Vehicle): def move(self): print("Plane is flying ✈️")
hero1 = Superhero("Captain Code", "Programming", "Bugs") hero2 = FlyingHero("Sky Soarer", "Flight", "High Altitude", 900) hero3 = StrengthHero("Mighty Muscle", "Super Strength", "Kryptonite", 100)
print("\nSuperheroes:") hero1.display_info() hero1.action()
hero2.display_info() hero2.action()
hero3.display_info() hero3.action()
dog = Dog() bird = Bird() car = Car() plane = Plane()
print("\nPolymorphism Challenge:") for obj in (dog, bird, car, plane): obj.move()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Base class for Superheroes
class Superhero:
def init(self, name, power, weakness):
self.name = name
self.power = power
self.weakness = weakness
Inheritance to explore polymorphism
class FlyingHero(Superhero):
def init(self, name, power, weakness, flight_speed):
super().init(name, power, weakness)
self.flight_speed = flight_speed
class StrengthHero(Superhero):
def init(self, name, power, weakness, strength_level):
super().init(name, power, weakness)
self.strength_level = strength_level
Base class for animals
class Animal:
def move(self):
print("Animal is moving")
Inherited classes for specific animals
class Dog(Animal):
def move(self):
print("Dog is running 🐕")
class Bird(Animal):
def move(self):
print("Bird is flying 🕊️")
Base class for vehicles
class Vehicle:
def move(self):
print("Vehicle is moving")
Inherited classes for specific vehicles
class Car(Vehicle):
def move(self):
print("Car is driving 🚗")
class Plane(Vehicle):✈️ ")
def move(self):
print("Plane is flying
Creating objects for Superheroes
hero1 = Superhero("Captain Code", "Programming", "Bugs")
hero2 = FlyingHero("Sky Soarer", "Flight", "High Altitude", 900)
hero3 = StrengthHero("Mighty Muscle", "Super Strength", "Kryptonite", 100)
Display information and actions for Superheroes
print("\nSuperheroes:")
hero1.display_info()
hero1.action()
hero2.display_info()
hero2.action()
hero3.display_info()
hero3.action()
Creating objects for animals and vehicles
dog = Dog()
bird = Bird()
car = Car()
plane = Plane()
Demonstrate polymorphism
print("\nPolymorphism Challenge:")
for obj in (dog, bird, car, plane):
obj.move()
The text was updated successfully, but these errors were encountered: