elena1234

Multiple inheritance in Python

Feb 5th, 2022 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. class User():
  2.     def sign_in(self):
  3.         print("logged in...")
  4.        
  5.    
  6. class Wizard(User):
  7.     def __init__(self, name, power):
  8.         self.name = name
  9.         self.power = power
  10.    
  11.     def attack(self):
  12.         print(f"{self.name} attacking with power of {self.power}.")
  13.        
  14.  
  15. class Archer(User):
  16.     def __init__(self, name, num_arrows):
  17.         self.name = name
  18.         self.num_arrows = num_arrows
  19.    
  20.     def attack(self):
  21.         print(f"{self.name} attacking with arrows: arrows left - {self.num_arrows}.")
  22.  
  23.  
  24. class HybridBorg(Wizard, Archer):
  25.     def __init__(self, name, power, num_arrows):
  26.          Wizard.__init__(self, name, power)
  27.          Archer.__init__(self, name, num_arrows)
  28.          
  29.     def attack(self):
  30.         print(f"{self.name} attacking with power of {self.power}.")
  31.         print(f"{self.name} attacking with arrows: arrows left - {self.num_arrows}.")
  32.  
  33.        
  34.  
  35. borg1 = HybridBorg("Borg_One", 500, 1000)
  36. print(borg1.name)
  37. print(borg1.power)
  38. print(borg1.num_arrows)
  39. print(borg1.attack())
Add Comment
Please, Sign In to add comment