python基础37讲课后动手作业有疑问,求解答
class Ticket():def __init__(self, weekend=False, child=False): Weekend=False 和Child=False是不是设定函数的这两个变量默认是False,与if语句设它们为true不冲突的
self.exp = 100
if weekend: #
self.inc = 1.2
else:
self.inc = 1
if child: #这两句是不是省略了‘= True’
self.discount = 0.5
else:
self.discount = 1
def calcPrice(self, num):
return self.exp * self.inc * self.discount * num
>>> adult = Ticket()
>>> child = Ticket(child=True)
>>> print("2个成人 + 1个小孩平日票价为:%.2f" % (adult.calcPrice(2) + child.calcPrice(1)))
2个成人 + 1个小孩平日票价为:250.00
if weekend:就是if weekend == True: 冬雪雪冬 发表于 2020-2-9 22:36
if weekend:就是if weekend == True:
万分感谢{:5_109:}
页:
[1]