# python-week05 **Repository Path**: wingyan/python-week05 ## Basic Information - **Project Name**: python-week05 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ``` product_list = [ ('IPAD AIR',4799), ('Mac Pro',16000), ('Lancome foundation',430), ('head first python',128), ('milk tea',18) ] shopping_car = [] alipay =int(input("请输入支付宝余额:")) while True: for item in product_list: print(product_list.index(item),item) choice = input("请输入商品编号:") if choice.isdigit(): choice = int(choice) if choice >= 0 and choice < 5: if alipay >= product_list[choice][1]: alipay = alipay - product_list[choice][1] print("已添加 %s 进你的购物车,您的余额为%s"%(product_list[choice],alipay)) print("如需继续购物则输入商品编号,不需要购买其他物品请按") shopping_car.append(product_list[choice]) else: print("你的余额不足,请选择其他商品或按'q'退出") else: print("商城里没有这个东西,你可以按'q'退出") elif choice == 'q': print("-----购物清单-----") print(shopping_car) print("您的支付宝余额为:%s"%(alipay)) break else: print("请输入编号或按'q'退出") else: print("请输入正确的余额") ``` ``` 输出结果: 请输入支付宝余额:3000 0 ('IPAD AIR', 4799) 1 ('Mac Pro', 16000) 2 ('Lancome foundation', 430) 3 ('head first python', 128) 4 ('milk tea', 18) 请输入商品编号:2 已添加 ('Lancome foundation', 430) 进你的购物车,您的余额为2570 如需继续购物则输入商品编号,不需要购买其他物品请按 0 ('IPAD AIR', 4799) 1 ('Mac Pro', 16000) 2 ('Lancome foundation', 430) 3 ('head first python', 128) 4 ('milk tea', 18) 请输入商品编号:q -----购物清单----- [('Lancome foundation', 430)] 您的支付宝余额为:2570 ```