每日題記17
阿新 • • 發佈:2018-07-25
clas print 雅馬哈 創建 打了 nature 分別是 sid rom
#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()
每日題記17