18 lines
468 B
Python
18 lines
468 B
Python
|
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 calc(self,num):
|
|||
|
P=self.exp*self.inc*self.discount*num
|
|||
|
return P
|
|||
|
|
|||
|
adult=ticket()
|
|||
|
child=ticket(child=True)
|
|||
|
print("2个成人+1个小孩平日票价为:%.2f"%(adult.calc(2)+child.calc(1)))
|