我正在尝试编写一个程序,在这个程序中,计算机从一个预定义的列表中选择一个单词,然后用户逐个输入字母来尝试猜测这个单词。你知道吗
我正在尝试循环程序,这样用户就可以不断猜测单词中的字母数,而不管他们猜测是否正确。你知道吗
然而,由于某些原因,如果他们猜对了,程序目前只循环两次,如果他们猜错了,则根本不会循环。我做错什么了?你知道吗
user_input = str(input("Please pick a letter you think is in the word I have chosen."))
for i in (0, len(computer_choice)) #computer_choice is the word the computer has generated
if user_input in WordList:
user_input = str(input("You got one of the letters! Keep going!"))
else:
user_input = str(input("You did not get one of the letters. Please try again. You have " + str(i) + " attempts left."))
您需要做的是请求用户在for循环中随机猜测字母,该循环从0运行到变量“computer choice”中存储的单词长度,如下所示:
不是100%确定你在追求什么,但这段代码循环游戏,直到用户输入一个不正确的字母
相关问题 更多 >
编程相关推荐