python/2024-11-1-2.py

18 lines
468 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)))