所以我的代码做了我想让它做的事情,但我相信有一种更简单的方法可以做到这一点,您可以立即获取与输入相关的价格。我只是不知道怎么做,here是原始说明
service1 = 'Oil change'
service2 = 'Tire rotation'
service3 = 'Car wash'
name1 = 'oil change'
name2 = 'tire rotation'
name3 = 'car wash'
price1 = 35
price2 = 19
price3 = 7
auto_service = input('Enter desired auto service:\n')
if auto_service in service1:
print('You entered: {}'.format(service1))
print('Cost of {}: ${}'.format(name1, price1))
elif auto_service in service2:
print('You entered: {}'.format(service2))
print('Cost of {}: ${}'.format(name2, price2))
elif auto_service in service3:
print('You entered: {}'.format(service3))
print('Cost of {}: ${}'.format(name3, price3))
else:
print('You entered: {}'.format(auto_service))
print('Error: Requested service is not recognized')
是的,使用带有服务价格对的dict
我将让您了解如何实现它,因为这是一个家庭作业,但这里有一个片段至少可以让您开始:
if auto_service.lower() in services:
相关问题 更多 >
编程相关推荐