名称错误:名称';宠物&x27;没有定义。python
这是我正在使用的代码,但每次我尝试运行它时,终端中都会出现以下错误:名称错误:名称';宠物&x27;没有定义。python,python,nameerror,Python,Nameerror,这是我正在使用的代码,但每次我尝试运行它时,终端中都会出现以下错误: Traceback (most recent call last): File "ex11.py", line 16, in <module> if pets == "y": NameError: name 'pets' is not defined 您的问题是,如果“Good”不在emotion中,pets不会被定义。因此,首先定义它: print "So, how are you doing to
Traceback (most recent call last):
File "ex11.py", line 16, in <module>
if pets == "y":
NameError: name 'pets' is not defined
您的问题是,如果
“Good”
不在emotion
中,pets
不会被定义。因此,首先定义它:
print "So, how are you doing today?"
emotion = raw_input()
pets = "n" #here
if "Good" in emotion:
print "Cool! I love when people are \"good\"! It makes me feel all fuzzy inside. ^-^"
print "Do you have any pets? y/n."
pets = raw_input()
if pets == "y":
print "Awesome! I have always wanted a pet! What kind do you have? What does it look like?"
pet_type = raw_input()
您的问题是,如果
“Good”
不在emotion
中,pets
不会被定义。因此,首先定义它:
print "So, how are you doing today?"
emotion = raw_input()
pets = "n" #here
if "Good" in emotion:
print "Cool! I love when people are \"good\"! It makes me feel all fuzzy inside. ^-^"
print "Do you have any pets? y/n."
pets = raw_input()
if pets == "y":
print "Awesome! I have always wanted a pet! What kind do you have? What does it look like?"
pet_type = raw_input()
提示:当情感中的“好”返回时会发生什么?提示:当情感中的“好”返回时会发生什么?