# Python_shppingcar hw **Repository Path**: ifishes/python_shppingcar-hw ## Basic Information - **Project Name**: Python_shppingcar hw - **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-25 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### shoppingcar 代码片段 ``` product_list = [('华为P30',4000), ('Mac pro',16000), ('milk tea',28), ('crabs',88), ('bike',400), ('watch',40000), ('head first python',128), ('book',40)] shopping_car = [ ] zhifubao = input('请输入支付宝的余额:') if zhifubao.isdigit(): zhifubao = int(zhifubao) 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 < 8: if zhifubao >= product_list[choice][1]: zhifubao = zhifubao - product_list[choice][1] shopping_car.append(product_list[choice]) print('你把商品%s添加到了购物车,你的支付宝余额是%s:'%(product_list[choice][0],zhifubao)) else: print('你的支付宝余额不足,请重新选择商品') else: print('商品列表里没有这个商品,请重新选择一个商品') elif choice =="q": print('----购物车清单----') for item in shopping_car: print(item) print('你的支付宝余额%s:'% zhifubao) break else: print('按q退出程序') else: print('请输入数字金额') ``` ### 运行结果 ![shoppingcar](01.png)