product_list = [ [‘Iphone‘,5888], [‘Mac Air‘,8000], [‘XiaoMi‘,19.9], [‘coffee‘,30], [‘Tesla‘,820000], [‘Bike‘,700], [‘Cloth‘,200], ] l=[] shop_car=[] salary=int(input("请输入您的工资: ")) while True: index=0 for i in product_list: print(index,i) index+=1 choice=input("请输入商品编号 w保存,q 退出: ") if choice.isdigit(): choice=int(choice) if choice > 0 and choice <= len(product_list): product=product_list[choice] if salary >= product[1]: shop_car.append(product) salary -= product[1] else: print("余额不足") else: print("您输入的商品编号不存在") elif choice == ‘w‘: print("---已经购买的商品列表---") l=[] for i in shop_car: if i not in l: l.append(i) l.append(shop_car.count(i)) print(l) print("您的余额 %s" % salary) print("end-----------") break else: exit("退出程序")
时间: 2024-12-29 21:03:46