python的第一个代码,写了2天。我的天呢

 简单购物车

 

Commodity_list = [("Book", 80),
                  ("Clothes", 200),
                  ("Computer", 3000),
                  ("Fruit", 30),
                  ]
shopping_cate = []
salary = input("Input your money:")
if salary.isdigit():
    salary = int(salary)
    while True:
        for index, item in enumerate(Commodity_list):
            print(index, item)
        choice_list = input('What to by?')
        if choice_list.isdigit():
            choice_list = int(choice_list)
            if choice_list <= len(Commodity_list) and choice_list >= 0:
                Item = Commodity_list[choice_list]
                if salary >= Item[1]:
                    shopping_cate.append(Item)
                    salary -= Item[1]

                    print("Add %s into your shopping cate,your blance is %d " %(Item,salary))
                else:

                    print('Your not have blance!')
            else:
                print('Input is wrong :')

        elif choice_list == 'q':
            print('----shopping cate-----')
            for i in shopping_cate:
                print(i)
            print('Thank,you,for,your,patronage')
            exit()

 

posted @ 2018-04-01 10:59  Smalllv  阅读(135)  评论(0编辑  收藏  举报