NP46. 菜品的价格
描述
输入描述
输入一个字符串表示菜品。输出描述
输出该菜品的价格。示例1
输入:
pizza
输出:
10
Python 3 解法, 执行用时: 30ms, 内存消耗: 4580KB, 提交时间: 2022-08-05
price = {'pizza':10,'rice':2,'yogurt':5,'others':8} str1 = input() if str1 not in price.keys(): str1 = 'others' for i in price.keys(): if i==str1: print(price[i]) break
Python 3 解法, 执行用时: 31ms, 内存消耗: 4548KB, 提交时间: 2022-07-27
foods = { 'pizza':10,'rice':2 ,'yogurt':5} food = input('') if food in foods.keys(): print(foods.get(food)) else: print(8)
Python 3 解法, 执行用时: 32ms, 内存消耗: 4472KB, 提交时间: 2022-08-01
s = input() if s == 'pizza': print('10') elif s == 'rice': print('2') elif s == 'yogurt': print('5') else: print('8')
Python 3 解法, 执行用时: 32ms, 内存消耗: 4504KB, 提交时间: 2022-07-30
food = input() if food == 'pizza': print(10) elif food == 'rice': print(2) elif food == 'yogurt': print(5) else: print(8)
Python 3 解法, 执行用时: 32ms, 内存消耗: 4512KB, 提交时间: 2022-08-06
food = input() if food == "pizza": print(10) elif food == "rice": print(2) elif food == "yogurt": print(5) else: print(8)