#定义一个游乐场买票的类,成人平日票价100,儿童半价,周末为平日的120%
class Ticket:
def __init__(self,weekend=False,child=False):
self.exp=100
if weekend:
self.inc=1.2
else:
self.inc=1
if child:
self.discount=0.5
else:
self.discount=1
def mannum(self,num):
return self.exp*self.inc*self.discount*num
Python-类01(计算买票问题)
最新推荐文章于 2025-03-09 00:15:00 发布