Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7错误:name';葡萄酒';没有定义_Python - Fatal编程技术网

Python 2.7错误:name';葡萄酒';没有定义

Python 2.7错误:name';葡萄酒';没有定义,python,Python,每当运行以下代码时,我都会收到错误消息“NameError:name'wine'未定义”: 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 t

每当运行以下代码时,我都会收到错误消息“NameError:name'wine'未定义”:

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"]
任何帮助都将不胜感激

试试看:

raw_input()
而不是:

input()

问题是您的输入正在被评估。这是Python2.x中
input()
的行为。由于没有名为
wine
的变量,因此会引发异常。您可以通过键入
“Wine”
(带双引号)来检查此行为,这很好,因为它现在是作为字符串而不是变量名输入的

您可以改用
raw_input()
,它将与您的值
Wine
一起使用,即:

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

您可能正在使用python 2.7

对于Python2.7,“输入”是“原始输入”

将输入函数替换为

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

这真的是整个剧本吗;这就是问题所在。我在实验室里使用的是Python3.5,但忘了家里的电脑上安装了一个旧版本。谢谢大家的帮助!