码迷,mamicode.com
首页 > 其他好文 > 详细

子类与父类

时间:2020-08-21 16:42:16      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:cheng   port   战斗   战斗机   and   扫描   父类   else   range   

import random

class feiji:
changdu = ‘20米‘
wuqi = ‘‘
licheng = ‘1000千米‘
zaizhong = "20吨"
xueliang = 1
def feixing(self):
print(‘开始飞行‘)
def jiayou(self):
print(‘开始加油‘)

class zhandouji(feiji):
num = 1
changdu = ‘5米‘
licheng = ‘500千米‘
zaizhong = "10吨"
xueliang = 3
def init(self,num,wuqi = ‘导弹‘):
self.wuqi = wuqi
self.num = num
def kaihuo(self):
print(self.num,‘号战斗机开始发射‘,self.wuqi )
def zhongdan(self):
self.xueliang = self.xueliang - 1

class yunshuji(feiji):
def init(self,huowu = ‘兵‘):
self.huowu = huowu
changdu = ‘30米‘
licheng = ‘2000千米‘
zaizhong = "100吨"
xueliang = 10
def zhuanghuo(self):
print(‘开始装‘ + self.huowu)
def xiehuo(self):
print(‘开始空投‘+self.huowu)
class wurenji(feiji):
def init(self, deren=‘敌人‘):
self.deren = deren
changdu = ‘3米‘
licheng = ‘2000千米‘
zaizhong = "0千克"
xueliang = 1
def xiehuo(self):
print(‘开始扫描‘+self.deren)

zhandoujiArr = []
for item in range(0,100):
zhandoujiArr.append(zhandouji(item))

for item in range(0,random.randint(1,5)):
zhandoujiArr[10].zhongdan()
if(zhandoujiArr[10].xueliang <= 0):
print(zhandoujiArr[10].num,‘号战斗机已被摧毁‘)
else:
print(zhandoujiArr[10].num,‘号战斗机血量还剩‘,zhandoujiArr[10].xueliang)

子类与父类

标签:cheng   port   战斗   战斗机   and   扫描   父类   else   range   

原文地址:https://blog.51cto.com/14887662/2521453

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!