【发布时间】:2021-12-17 09:35:39
【问题描述】:
sports_talk = False
sports = ["Basketball", "Football", "Soccer"]
sports_response = ["What sports do you play?", "what sports do you play?"]
hobbies = ["Programming", "Playing Sports", "Art", "Singing", "Playing the Piano", "Watching YouTube"]
def what_question_hobby(questions):
choice = random.choice(hobbies)
if choice == "Playing Sports":
sports_talk = True
print(sports_talk)
print("Bot: " + choice)
if sports_talk == True:
print("/hint ask him what sports he plays")
info = input("You: ")
if info in sports_response:
print("Bot: " + random.choice(sports))
sports_talk = False
while True:
talking_input = input("You: ")
if talking_input == "What do you enjoy?":
what_question_hobby(talking_input)
我不断收到此错误,但我不确定如何修复它UnboundLocalError: local variable 'sports_talk' referenced before assignment on line 56
【问题讨论】:
-
能否请您发布所有相关代码?此代码不包含调用
what_question_hobby()的位置或问题和爱好变量是什么。此代码本身不会导致错误。 -
尝试明确标题,将其余文本添加到正文(不是标题),指定您在哪一行出现错误Wich line is line 56?我>。也不清楚你在哪里调用这个函数。
-
@TadhgMcDonald-Jensen 没关系,非常感谢!
标签: python