子弹类
class Bullet():
def __init__ (self,bullet_count):
self.bullet_count=bullet_count
#枪类
class Gun():
def init(self,bullet):
self.bullet=bullet
def shoot(self,bullet_num):
if self.bullet.bullet_count>=bullet_num:
self.bullet.bullet_count-=bullet_num
print(“哒”*bullet_num,“还剩{}”.format(self.bullet.bullet_count))
else:
print("弹药不足")
#人的定义
class Person():
def __init__ (self,gun):
self.gun=gun
def fire(self,count):
self.gun.shoot(count)
def bullet_fill(self,num):
self.gun.bullet.bullet_count += num
print("子弹填充完毕")
return self.gun.bullet.bullet_count
bullet=Bullet(100)
jiatelin=Gun(bullet)
longwu =Person(jiatelin)
longwu.fire(8)