第十一次作业
作者:互联网
作业1
class QiaNg:
def __init__(self):
self.num = 0
def qiang(self):
self.name = input("请输入枪型号:")
def zidan(self):
self.num = int(input("请输装填子弹数量:"))
while True:
if self.num > 0:
print('射击')
self.num -= 1
else:
print('没有子弹,无法射击')
break
class ShiBing(QiaNg):
def __init__(self):
self.Qnum = 0
self.Bingname()
self.qiangshu()
self.zhunbei()
def Bingname(self):
self.Bname = input("请输入士兵名字:")
def qiangshu(self):
self.Qnum = int(input("请输入枪支数"))
def zhunbei(self):
if self.Qnum > 0:
print(f'拥有枪支数量为{self.Qnum}')
self.qiang()
self.zidan()
else:
print('你没有抢无法射击')
s = ShiBing()
作业2
class CheOne:
def __init__(self):
self.num = 4
self.sudu = 0
self.cheshujv()
self.jiasu()
def cheshujv(self):
self.yanse = input('请输入车辆颜色:')
self.zhong = input('请输入车重量级:')
def jiasu(self):
while True:
sudu1 = int(input("输入车速,正数为加速、负数为减速:"))
self.sudu += sudu1
if self.sudu >= 200:
self.sudu = 200
print('最高速了,车速最高200码')
break
else:
print(f'当前速度{self.sudu}')
if self.sudu < 0:
self.sudu = 0
print("停车了")
break
if self.sudu == 0:
print('停车状态')
break
class cheTwo(CheOne):
def __init__(self):
super().__init__()
self.jiasu()
self.shujv()
def jiasu(self):
while True:
sudu1 = int(input("输入车速,正数为加速、负数为减速:"))
self.sudu += sudu1
if self.sudu >= 300:
self.sudu = 300
print('最高速了,车速最高300码')
break
else:
print(f'当前速度{self.sudu}')
if self.sudu < 0:
self.sudu = 0
print("停车了")
break
if self.sudu == 0:
print('停车状态')
break
def shujv(self):
self.shujv = input('请输入车子品牌和型号:')
print(f'车子牌子和型号:{self.shujv},车子颜色:{self.yanse},重量级:{self.zhong}车轮:{self.num}')
s = cheTwo()
标签:__,第十一次,self,作业,sudu,print,input,def 来源: https://blog.csdn.net/yuuisei/article/details/113818752