假定一款游戏中,共有A B C D四种商品,每种商品的金币价格存在字典price={' A':20,' B':30,'C':40,' D':50}。编写一个程序输入一个金币值以及若干商品名称判断若能购买这些商品则输出yes,否则则输出no。
3条回答 默认 最新
- threenewbee 2023-04-04 10:44关注
稍等,帮你写,人工回答,需要时间。
price = {'A': 20, 'B': 30, 'C': 40, 'D': 50} coin = int(input("")) items = input("").upper().split() total_price = sum([price[item] for item in items if item in price]) if total_price <= coin: print("yes") else: print("no")
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录