#1,暴力摩托程序(完成下列需求): # 1.1创建三个游戏人物,分别是: # 苍井井,女,18,攻击力ad为20,血量200 # 东尼木木,男,20,攻击力ad为30,血量150 # 波多多,女,19,攻击力ad为50,血量80 # 1.2创建三个游戏武器,分别是: # 平底锅,ad为20 # 斧子,ad为50 # 双节棍,ad为65 # # 1.3 创建三个游戏摩托车,分别是: # # 小踏板,速度60迈 # 雅马哈,速度80迈 # 宝马,速度120迈。 # # 完成下列需求(利用武器打人掉的血量为武器的ad + 人的ad): class GameRole: gamename="Race Stunt Fight! Motorcycles" gamers="两亿" gamenature="端游对战" def __init__(self,name,sex,age,ad,hp): self.name=name self.sex=sex self.age=age self.ad=ad self.hp=hp def attack(self,p): p.hp-=self.ad print("%s赤手空拳打了%s%s滴血,%s还剩%s血"%(self.name,p.name,self.ad,p.name,p.hp)) def game_equipment(self,equipment): self.equipment=equipment def bike(self,motorcycles): self.motorcycles=motorcycles def add_bike(self,p): p.hp = p.hp - self.ad - self.equipment.ad print("%s骑着%s打了骑着%s的%s一%s,%s哭了,%s还剩%s血" % (self.name,self.motorcycles.name,p.motorcycles.name,p.name,self.equipment.name,p.name,p.name,p2.hp)) class Shop: def __init__(self,name,ad): self.name=name self.ad=ad def slaughter(self,p1,p2): p2.hp=p2.hp-self.ad-p1.ad print("%s利用%s打了%s一%s,%s还剩%s点血量"%(p1.name,self.name,p2.name,self.name,p2.name,p2.hp)) def bike_slaughter(self,p1,p2,m1,m2): p2.hp = p2.hp - self.ad - p1.ad print("%s骑着%s打了骑着%s的%s一%s,%s哭了,%s还剩%s血"%(p1.name,m1.name,m2.name,p2.name,self.name,p2.name,p2.name,p2.hp)) class Motorcycles: def __init__(self,name,speed): self.name=name self.speed=speed def go_bike(self,p): print("%s骑着%s开着%s迈的车行驶在赛道上"%(p.name,self.name,self.speed)) p1=GameRole("苍井井","女",18,20,200) p2=GameRole("东尼木木","男",20,30,150) p3=GameRole("波多多","女",19,50,80) s1=Shop("平底锅",20) s2=Shop("斧子",50) s3=Shop("双节棍",65) m1=Motorcycles("小踏板",60) m2=Motorcycles("雅马哈",80) m3=Motorcycles("宝马",120) # (1)苍井井骑着小踏板开着60迈的车行驶在赛道上。 # p1.bike(m1) # p1.motorcycles.go_bike(p1) # (2)东尼木木骑着宝马开着120迈的车行驶在赛道上。 # p2.bike(m3) # p2.motorcycles.go_bike(p2) # (3)波多多骑着雅马哈开着80迈的车行驶在赛道上。 # p3.bike(m2) # p3.motorcycles.go_bike(p3) # (4)苍井井赤手空拳打了波多多20滴血,波多多还剩xx血。 # p1.attack(p3) # (5)东尼木木赤手空拳打了波多多30滴血,波多多还剩xx血。 # p2.attack(p3) # (6)波多多利用平底锅打了苍井井一平底锅,苍井井还剩xx血。 # p3.game_equipment(s1) # p3.equipment.slaughter(p3,p1) # (7)波多多利用斧子打了东尼木木一斧子,东尼木木还剩xx血。 # p3.game_equipment(s2) # p3.equipment.slaughter(p3,p2) # (8)苍井井骑着宝马打了骑着小踏板的东尼木木一双节棍,东尼木木哭了,还剩xx血。 # 波多多骑着小踏板打了骑着雅马哈的东尼木木一斧子,东尼木木哭了,还剩xx血。 p1.bike(m3) p2.bike(m1) p1.game_equipment(s3) p1.add_bike(p2) # p1.equipment.bike_slaughter(p1,p2,m3,m1) # p3.bike(m1) # p2.bike(m2) # p3.game_equipment(s2) # p3.equipment.bike_slaughter(p3,p2,m1,m2) # 2,定义一个类,计算圆的周长和面积。 from math import pi class Circular: def __init__(self,radius): self.radius=radius def perimeter(self): return 2*pi*self.radius def area(self): return pi*self.radius*self.radius # # r1=Circular(4) # # r1.perimeter() # # r1.area() class Ring: def __init__(self, radius_outside, radius_inside): self.outside_circular = Circular(radius_outside) self.inside_circular = Circular(radius_inside) def perimeter(self): C=self.outside_circular.perimeter() + self.inside_circular.perimeter() print("该环型的周长为%s" % C) def area(self): S= self.outside_circular.area() - self.inside_circular.area() print("该环型的面积为%s" % S) ring=Ring(5,10) ring.perimeter()