sibinasto

2. Weapon

Mar 3rd, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # Ines
  2.  
  3. class Weapon:
  4.     def __init__(self, bullets):
  5.         self.bullets = bullets
  6.  
  7.     def shoot(self):
  8.         if self.bullets:
  9.             self.bullets -= 1
  10.             return 'shooting...'
  11.         return f"no bullets left"
  12.  
  13.     def __repr__(self):
  14.         return f"Remaining bullets: {self.bullets}"
  15.  
  16.  
  17. weapon = Weapon(5)
  18. print(weapon.shoot())
  19. print(weapon.shoot())
  20. print(weapon.shoot())
  21. print(weapon.shoot())
  22. print(weapon.shoot())
  23. print(weapon.shoot())
  24. print(weapon)
Advertisement
Add Comment
Please, Sign In to add comment