Fileshopping
来源:互联网 发布:淘宝卖aj的正品店 编辑:程序博客网 时间:2024/06/11 09:04
完成文件解析,再进行购物车作业
f = open('Fileshopping','w',encoding='utf-8')f.write('电脑 1999\n鼠标 10\n游艇 20\n美女 998\n')f.close()f = open('Fileshopping',encoding='utf-8')shop_list = []for line in f: shop_dict = {'name': None, 'price': None} # line = line.strip() # 没用的吗 if line.strip(): list1 = line.split() shop_dict['name'] = list1[0] shop_dict['price'] = list1[1] shop_list.append(shop_dict)f.close()# print(shop_list) # 不用的shopping_list = []l = []total = input('请输入你所有的钱:')while True: if total.isdigit(): if int(total) > 10: for i in range(1,5): if int(total) >= int(shop_list[i-1]['price']): print(i,shop_list[i-1]['name'],shop_list[i-1]['price']) l.append(i) choice = input('请输入要选择的商品的序号:') if choice.isdigit(): choice = int(choice) # if l.find(choice+1) != -1: if choice <= 4: if int(total) >= int(shop_list[choice - 1]['price']): total = int(total) - int(shop_list[choice - 1]['price']) shopping_list.append(shop_list[choice - 1]['name']) print(shop_list[choice - 1]['name'],'已加入购物车,您还剩',total,'元钱') total = str(total) elif int(total) < int(shop_list[choice - 1]['price']): print('余额不足,请选购以下商品:') else: print('请重新输入正确数字序号') else: print('请重新输入正确数字序号') elif choice.upper() == 'Q': break else: print('请输入正确指令') else: print('余额不足啦,已自动为你退出') break elif total.upper() == 'Q': break else: print('请输入正确指令')print('您已经购买:',shopping_list)
阅读全文
0 0
- Fileshopping
- QT中eventFilter的使用方法
- Python入门——数据类型
- 使用QT来绘制MAT
- C++11的强类型枚举
- 3Sum Closest
- Fileshopping
- RPFS(RP First Search) 模拟退火算法 未完
- easyui datagrid 添加操作列时设计到rowdata传参问题
- Wannafly 牛客网 挑战赛2 A
- PullToRefreshListView
- 【bzoj 2044】三维导弹拦截(网络流)(拓扑排序)
- Sklearn-train_test_split随机划分训练集和测试集
- leetcode 25. Reverse Nodes in k-Group
- ReactNative——动画学习