|  | 
 
| 
class ticket():
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 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 caluPrice(self, num):
 return self.exp*self.inc*self.discount*num
 
 num1=int(input('enter the adult number:'))
 num2=int(input('enter the child number:'))
 
 adult=ticket()
 child=ticket(child=True)
 print('%d个成人+%d个儿童的总费用为:%.2f'%(num1,num2,adult.caluPrice(num1)+child.caluPrice(num2)))
 
 
 adult=ticket(weekend=True)
 print('因为是周末,所以%d个成人的总费用为:%.2f'%(num1,adult.caluPrice(num1)))
 
 通过增加num的自然输入,可以很简便的统计到不同 人数的票价总花费是多少
 
 | 
 |