Advertisement
ClearCode

dunder

Apr 27th, 2022
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. class Monster:
  2.  
  3.     def __init__(self,health,energy):
  4.         self.health = health
  5.         self.energy = energy
  6.  
  7.     def __len__(self):
  8.         return self.health
  9.  
  10.     def __abs__(self):
  11.         return self.energy
  12.  
  13.     def __call__(self):
  14.         print('The monster was called')
  15.  
  16.     def __add__(self,other):
  17.         return self.health + other
  18.  
  19.     def __str__(self):
  20.         return f'A monster with health {self.health} and energy {self.energy}'
  21.  
  22.     # methods
  23.     def attack(self,amount):
  24.         print('The monster has attacked!')
  25.         print(f'{amount} damage was dealt')
  26.         monster.energy -= 20
  27.         print(self.energy)
  28.  
  29.     def move(self,speed):
  30.         print('The monster has moved')
  31.         print(f'It has a speed of {speed}')
  32.  
  33. monster1 = Monster(10,20)
  34. print(str(monster1))
  35. print(monster1)
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement