import random
right = 0
num = 1
W = ['play', 'guess', 'english']
repeat = 'yes'
while num < len(W)+ 1:
word = random.choice(W)
word1 =word
answer = word
a = ''
for i in word:
postion = random.randrange(len(word))
a += word[postion]
word = word[0:postion] + word[(postion+1):]
print("乱序后的单词:", a)
guess = input("输入你的猜测:")
while guess != answer:
guess = input("重新猜测:")
print("猜对了")
W.remove(word1)
right += 1
print("一共猜对了{}个词".format(right))
print("游戏结束")
望采纳!谢谢
while(len(W)!=0):
然后right+=1底下插入
for i in range(len(W)):
if W[i] == answer:
del W[i]
break
有这么几个问题,
第一,保证不重复可以通过W.remove(word)实现每次删除猜完的词
第二,按你目前的逻辑应该只能猜无数轮,因为num从1开始,没有增加,一直都是1,会导致第一个循环死循环
第三,按你目前的逻辑,猜不对就重猜,必须猜对才能进入下一个,似乎不合适
W.remove(guess)