当我运行此命令时,经过一些正确的猜测,它会打印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提供。