1. #!/bin/env python
    2. # encoding=utf-8
    3. import sys
    4. goods_list = dict(苹果=100, 矿泉水=150, 饮料=200, 香烟=100, 面包=120, 哇哈哈=300, 大碗面=400, 康师傅=100, 酸酸乳=120)
    5. class Custom(object):
    6. def __init__(self, customer_type, goods=None):
    7. """
    8. :param customer_type: 1 vip,2 普通
    9. :param goods:
    10. """
    11. self.customer_type = customer_type
    12. if goods is None:
    13. goods = {}
    14. self.goods = goods
    15. def buy(self):
    16. if self.customer_type == '1':
    17. self.vip_pay_up()
    18. if self.customer_type == '2':
    19. self.custom_pay_up()
    20. def vip_pay_up(self):
    21. # 结账
    22. account = 0
    23. for item in self.goods:
    24. sales = goods_list[item]
    25. account = account + sales
    26. if account >= 200:
    27. print('共计消费:', account * 0.8, '元,折扣8折')
    28. elif len(goods_list) >= 10:
    29. print('共计消费:', account * 0.85, '元,折扣85折')
    30. else:
    31. print('共计消费:', account, '元')
    32. def custom_pay_up(self):
    33. # 结账
    34. account = 0
    35. for item in self.goods:
    36. sales = goods_list[item]
    37. account = account + sales
    38. if account < 200:
    39. print('共计消费:', account, '元')
    40. if account >= 200:
    41. print('共计消费:', account * 0.9, '元,折扣9折')
    42. if __name__ == '__main__':
    43. message = print('Please choice vip or customer.')
    44. #选择会员还是普通客户
    45. inform = 'vip'
    46. if inform == 'vip':
    47. custom1 = Custom('1', goods_list)
    48. custom1.buy()
    49. if inform == 'customer':
    50. customer2 = Custom('2', goods_list)
    51. customer2.buy()