|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码无法运行,但不知道错在哪里,希望大神指教
代码运行显示错误如下:
>>> a = T(adult =2,child = 0)
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
a = T(adult =2,child = 0)
File "C:/Users/lxx/Desktop/python练习题/票价计算.py", line 13, in __init__
self.adultprice = self.price * self.adult
AttributeError: 'T' object has no attribute 'adult'
代码如下:
class T():
def __init__(self,day = "day",adult = 0,child = 0):
self.dayprice = 100
self.wenkeenprice = self.dayprice * 1.2
self.childprice = self.dayprice / 2
if day == "day":
self.price = self.dayprice
else:
self.price = self.wenkeenprice
self.adultprice = self.price * self.adult
self.childprrice = (self.price * self.child) / 2
def countprice(self):
self.num = self.manprice + self.childprice
print(self.num)
- def __init__(self, day="day", adult=0, child=0):
- self.dayprice = 100
- self.wenkeenprice = self.dayprice * 1.2
- self.childprice = self.dayprice / 2
- self.day = day
- self.adult = adult
- self.child = child
- if day == "day":
- self.price = self.dayprice
- else:
- self.price = self.wenkeenprice
- self.adultprice = self.price * self.adult
- self.childprrice = (self.price * self.child) / 2
复制代码
__init__()里要加几句。
|
|