我正在练习一些Python,我在尝试比较用户输入在hangman游戏中选择的单词时遇到了一些困难。在
# User guess input (single char)
# Exception handling to limit input to letters between a-z
while True:
userInput = str(input('Please guess a letter:'))
if len(userInput) == 1:
if not re.match("^[a-z]*$", userInput):
print("Error! Only letters a-z allowed!")
continue
break
else:
print("Error! Please input a single letter!")
continue
# Comparing array with input
for i in range(len(selWord)):
if(userInput == selWord[i]):
问题在于最后一行:
^{pr2}$它声明“名称‘userInput’没有被定义。”但是当我试图在初始while循环之外打印时,它工作得很好。在
这就是解决办法,谢谢大家!在
相关问题 更多 >
编程相关推荐