Advertisement
simeonshopov

Weapon

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