简单购物车
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()