Python初学者寻求代码评审与优化指导
Python购物代码评审请求
迭代需求
- V1.0:实现从各商店选一件商品并移除库存,最后打印已购商品
- V1.2:增加退出商店功能、金币支付与余额展示
- V1.4:修复BUG、代码重构
- V1.5:合并所有商店库存并打印采购前后的库存
自写代码
我是Python初学者,为测试自身现有水平,未参考任何资料编写了以下代码:
freelancers = {'name': 'freelancing Shop','brian': 70, 'black knight': 20, 'biccus diccus': 100, 'grim reaper': 500, 'minstrel': -15} antiques = {'name': 'Antique Shop','french castle': 400, 'wooden grail': 3, 'scythe': 150, 'catapult': 75, 'german joke': 5} pet_shop = {'name': 'Pet Shop','blue parrot': 10, 'white rabbit': 5, 'newt': 2} all_stores = {} cart_total = 1 cart = 'Items you\'ve purchased: ' stores_lst = {'freelancers':'', 'antiques':'', 'pet_shop':''} for stores in (freelancers, antiques, pet_shop): all_stores.update(stores) while cart_total <= 3: store = input(f'What store are you visiting?: {stores_lst.keys()}') if store == 'freelancers': item1 = input('What would you like from this store?: ' + str(sorted(freelancers))) all_stores.pop(item1) freelancers.pop(item1) cart = cart + " " + item1 cart_total += 1 del stores_lst['freelancers'] elif store.lower() == 'antiques': item2 = input('What would you like from this store?: ' + str(sorted(antiques))) all_stores.pop(item2) antiques.pop(item2) cart = cart + " " + item2 cart_total += 1 del stores_lst['antiques'] else: item3 = input('What would you like from this store?: ' + str(sorted(pet_shop))) all_stores.pop(item3) pet_shop.pop(item3) cart = cart + " " + item3 cart_total += 1 del stores_lst['pet_shop'] print(cart) print(all_stores)
诉求
现寻求资深开发者对代码进行评审,提供改进建议与更优实现方案,帮助提升编程技能。
内容的提问来源于stack exchange,提问作者gem's_dad
相关产品推荐
相关产品推荐

