我们如何将菜单中的所有价格增加10%。
代码:
burger = {'Fiery Pepper' : 5.65,'McSpicy':'4.85','Quarter Pounder':'4.20','Cheeseburger':'2.35'}
beverages = {'Hot Tea':2.60,'McCafe':2.70,'Coca-Cola':2.65}
menu ={}
menu.update(burger)
menu.update(beverages)
for key in sorted(menu):
print(key, '->', menu[key]
答案 0 :(得分:3)
将它们乘以 1.1
(或原来的 110%):
burgers = {k: float(v) * 1.1 for k, v in burgers.items()}
beverages = {k: float(v) * 1.1 for k, v in beverages.items()}