2015-04-04 63 views
0

我得到错误信息“NameError:名字‘酒’没有定义”每当我运行下面的代码:的Python 2.7的错误:名称“酒”是没有定义

def pub(): 
print ("Welcome to the pub; what will you be drinking tonight?") 
answer = input("Choose the type of beverage you desire") 
if answer == " Beer" or answer == " beer": 
    print ("You've come to the right place; have a seat!") 
elif answer == " Wine" or answer == " wine": 
    print ("Sorry, we don't serve wine here. Why don't you try next door?") 
elif answer == " Cocktails" or answer == " cocktails" : 
    print ("Cocktails? who drinks those anymore?") 
elif answer == " Liquor" or answer == " liquor": 
    print ("Sorry, we don't serve hard drinks here.") 
else: 
    print ("You didn't pick a legitimate drink; try again!") 
pub() 
def beer_selection(): 
    print ("Now we need to know what types of beers you're into. Select one of  the \ 
following flavor profiles:") 
flavor_profiles = ["Rich and malty", "Crisp and hoppy", "Light and fruity", "Smooth and balanced", "Piney and hoppy"] 

任何帮助将不胜感激!

+2

是不是真的整个脚本? – peterh 2015-04-04 05:15:11

回答

1

尝试:

raw_input() 

代替:

input() 
1

的问题是,你的输入被评估。这是Python 2.x中的input()的行为。由于您没有名为wine的变量,因此会引发异常。您可以通过输入" Wine"(使用双引号)来检查此行为,该工作正常,因为它现在以字符串而不是变量名输入。

您可以使用raw_input(),它知道你的价值Wine,即工作:

answer = raw_input("Choose the type of beverage you desire") 
0

你可能会使用Python 2.7

为Python 2.7的 '输入' 是 '的raw_input'

用此代替输入功能

answer = raw_input("Choose the type of beverage you desire:") 
+1

好的;这是问题。我在实验室中使用了python 3.5,并忘记了我的电脑上安装了旧版本。感谢大家的帮助! – durkadork 2015-04-05 22:21:00

相关问题