python/2024-11-1-2.py

18 lines
468 B
Python
Raw Permalink Normal View History

2025-01-08 09:17:08 +08:00
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)))