7-7 sdut-oop-7 答答租车系统(类的继承与多态 面向对象综合练习)- -python
写了很多冗余数据:车型名称可以不要
class Che: id=0 name='A' maxpeo=0 weight=0 meo=0 def __init__(self,id,name,maxpeo,weight,meo): self.id=id self.name=name self.maxpeo=maxpeo self.meo=meo self.weight=weight def getMaxpeo(self,n): return self.maxpeo*n def getWeight(self,n): return self.weight*n def getMeo(self,n): return self.meo*n class KeChe(Che): def __init__(self,id,name,maxpeo,meo): self.id=id self.name=name self.maxpeo=maxpeo self.meo=meo class HuoChe(Che): def __init__(self,id,name,weight,meo): self.id=id self.name=name self.weight=weight self.meo=meo ans=[] ans.append(KeChe(1,"d",5,800)) ans.append(KeChe(2,"d",5,400)) ans.append(KeChe(3,"d",5,800)) ans.append(KeChe(4,"d",51,1300)) ans.append(KeChe(5,"d",55,1500)) ans.append(Che(6,"d",5,0.45,500)) ans.append(Che(7,"d",5,2.0,450)) ans.append(HuoChe(8,"d",3,200)) ans.append(HuoChe(9,"d",25,1500)) ans.append(HuoChe(10,"d",35,2000)) x=int(input()) if x==1: n=int(input()) sum1=0.0 sum2=0.0 sum3=0.0 for i in range(n): #a表示要租车的编号, #b表示租用该车型的天数。 a,b=map(int,input().split()) sum1+=ans[a-1].getMaxpeo(b) sum2+=ans[a-1].getWeight(b) sum3+=ans[a-1].getMeo(b) print(int(sum1),'%.2f' %sum2,int(sum3)) else: print("0 0.00 0")
本文作者:kingwzun
本文链接:https://www.cnblogs.com/kingwz/p/16336515.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步