2015-12-20 164 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

正是我需要非常感謝你 編輯:完美的作品 –

相關問題