【发布时间】:2018-08-13 10:57:27
【问题描述】:
所以,我是编程新手,目前正在学习 Python。
在尝试制作一个简单的游戏时,当我尝试将名为 user_answer 的变量更改为 input("Please, answer with yes or no.") 时遇到了困难。
基本上这是我的代码行else: user_answer = input("Please, answer with yes or no.")。
但由于某种原因,我收到一个错误,称为“未使用局部变量'user_answer'值”。
谁能帮我解决这个问题?
提前致谢!
这是我的完整代码:
def my_function():
user_answer = input("Would you like to play a game?")
if user_answer == "yes":
print("Great! I have a number in my head from 1 to 10. Make a guess!")
elif user_answer == "no":
print("Oh, okay! Maybe next time?")
else: user_answer = input("Please, answer with yes or no.")
my_function()
【问题讨论】:
-
这不是 Python 错误,可能只是来自 IDE 的警告。这可能是因为您在此之后不再使用
user_answer。 -
请注明您使用的是哪个IDE。
标签: python python-3.x