所以,我有以下Python:变量未定义?
def userinput():
adjective1 = input("Adjective: ")
noun1 = input("Noun: ")
noun2 = input("Noun: ")
def story():
print("A vacation is when you take a trip to some " + adjective1 + " place.")
print("Usually you go to some place that is near " + noun1 + " or up on " + noun2 + ".")
这个东西,然后当我运行的功能,并提供输入,它回来了
File "/Users/apple/Dropbox/MadLibs 6.py", line 52, in story
print("A vacation is when you take a trip to some " + adjective1 + " place with your "+ adjective2 + " family.")
NameError: name 'adjective1' is not defined
是什么这个意思,我怎么能解决这个问题?
你需要设置两个变量为全局。 –