2015-12-20 117 views
-1

这是我迄今为止编写的代码。正如你可以看到,如果你运行代码,我有一个问题,最后6行和他们的功能。如何检查输入是否与数组中的值匹配

kegsize = input('Please enter keg size. Litres: ') 
print (kegsize, 'Litres') 

netpurchasecost = input('Please enter net purchase cost. GBP: ') 
print ('£', netpurchasecost) 

abv = input('Please enter Alcohol by Volume. %: ') 
print (abv, '%') 

gp = input('Please enter Gross Profit Percentage. %: ') 
print (gp, '%') 

opt = print('These are the Portion Size options (imperial measurements), 1/3, 1/2, 2/3, 1') 
portionsize = input('Please choose Portion Size: ') 
if portionsize != ['1/3' , '1/2' , '2/3' , '1']: 
    print('Please enter a Portion Size from the list') 
else: 
    print(portionsize) 

不管是否我输入的“1/3”,“1/2”的部分的大小,“2/3”或“1”的外壳仍然会输出“请从输入部分的大小清单”。

回答

1

尝试

if portionsize not in ['1/3' , '1/2' , '2/3' , '1']: 
+0

正是我需要非常感谢你 编辑:完美的作品 –

相关问题