学习对象的时候做的练习,要求是人开火便会打印“还剩多少子弹”,为什么没有打印呢?初学小白请教各位大神
class BulletBox(object):
def __init__(self, num):
self.bulletNum = num
class Person(object):
def __init__(self, gun):
self.gun = gun
def fire(self):
self.gun.shoot
class Gun(object):
def __init__(self, box):
self.bulletBox = box
def shoot(self):
if self.bulletBox.bulletNum == 0:
print("没有子弹了")
else:
self.bulletBox.bulletNum -= 1
print("还剩%d发子弹" % self.bulletBox.bulletNum)
bulletBox = BulletBox(9)
gun = Gun(bulletBox)
person = Person(gun)
person.fire()