0
点赞
收藏
分享

微信扫一扫

python士兵突击_01_枪类

非凡兔 2022-03-11 阅读 71
class Gun:

    def __init__(self, model):
        # 1. 枪的型号
        self.model = model
        # 2. 子弹的数量
        self.bullet_count = 0

    def add_bullet(self, count):
        self.bullet_count += count

    def shoot(self):
        # 1. 判断子弹数量
        if self.bullet_count <= 0:
            print("[%s]没有子弹了..." % self.model)
            return
        # 2. 发射子弹
        self.bullet_count -= 1
        # 3. 提示发射信息
        print("[%s]突突突...[%d]" % (self.model, self.bullet_count))


ak47 = Gun("AK47")
ak47.add_bullet(50)
ak47.shoot()

举报

相关推荐

python士兵突击简单小程序

【python基础】01_认识Python

01_链表

01_学习笔记

01_公式篇

01_什么是微服务

ajax笔记_01_原生ajax

0 条评论