子手:仅需几次正确的猜测就可以注册为正确的人

时间:2019-03-11 21:49:32

标签: python-3.x

当我运行此命令时,经过一些正确的猜测,它会打印Prisoner Wins! 有人知道为什么吗?

num_letters=int(input('How many letters?'))

word_to_guess = []
for _ in range(num_letters):
    word_to_guess.append(
        input('Input your (lowercase) letter:').lower().strip())

word_to_show = ['?', ] * num_letters
fail = 0
good = 0

while fail < 7 and good < num_letters:
    guess = input('Guess a letter...').lower().strip()
    if guess in word_to_guess:
        print('Right!')
        good += 1

        for i, letter in enumerate(word_to_guess):
            if guess == letter:
                good+=1
                word_to_show[i] = letter
    else:
        print('No.')
        fail += 1

    print(word_to_show)

print('word_to_guess', word_to_guess)
print('word_to_show', word_to_show)
if fail == 7:
    print('Executioner wins!')
else:
    print('Prisoner wins!')

不一致。我尝试了多次,范围从2到6。另一件事:该代码由Ralf提供。

0 个答案:

没有答案