def show_price_list(user_choice):
if user_choice.lower() == 'single':
print(150)
elif user_choice.lower() == 'business':
print(300)
elif user_choice.lower() == 'couple':
print(500)
else:
print("未找到你所需要的房间类型")
show_price_list('couple')
代码没毛病,但不觉得重复感太强吗?我们能否换个方式来编码,like this:
PRICES = {'single': 150, 'business': 300, 'couple': 500}
def show_price_list(user_choice):
print(PRICES.get(user_choice.lower(), "未找到你所需要的房间类型"))
show_price_list('couple')