所以,我有以下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
是什麼這個意思,我怎麼能解決這個問題?
你需要設置兩個變量爲全局。 –