Python 水果店价格更新程序:添加、更新水果价格
cost= {'苹果':5.2,'山竹':12.9,'香蕉':2.4,'荔枝':15,'葡萄':9.3,'桂圆':8,'蓝莓':10,'李子':8}
fruit = input("请输入水果名称:") price = float(input("请输入水果价钱:"))
if fruit in cost: if cost[fruit] != price: print(f"{fruit}涨价了,现价{price}元") cost[fruit] = price else: print(f"{fruit}的价钱{price}元已上传") else: print(f"{fruit}的价钱{price}元已上传") cost[fruit] = price
print(cost)
原文地址: https://www.cveoy.top/t/topic/pnzi 著作权归作者所有。请勿转载和采集!