题目如图
怎么保证猜过的词不重复出现?
我想的是每次猜正确后就把这个词从字符串中去除掉,但是不知道代码怎么写,以及while循环的条件是什么,或者有更好的思路吗?
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("游戏结束")
望采纳!谢谢