Advertisement
Ulabael

класс

Mar 3rd, 2023 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. class Character(object):
  2.     def __init__(self, hp, hp_max):
  3.         self.hp = hp
  4.         self.hp_max = hp_max
  5.     def got_hit(self):
  6.         self.hp -= 5
  7.         print(self.hp)
  8.     def heal(self):
  9.         if self.hp + 10 <= self.hp_max:
  10.             self.hp += 10
  11.         print(self.hp)
  12.  
  13.  
  14. char = Character(50, 100)
  15. char.got_hit() # 45
  16. char.heal() # 55
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement