所以我正在做一个刽子手代码,如果他们提供的所有字符都在开头插入的单词中,我想显示获胜者文本。因此,当玩家猜到这个词时,我希望能够显示获胜文本。
到目前为止,这是我的代码:
word = input("Enter the word to guess: ")
ingame = True
guesslist = ''
while ingame == True:
guess = str(input("Guess a letter "))
guesslist += guess
for char in word:
if char in guesslist:
print(char, end=" ")
else:
print("_", end=" ")
提前致谢
答案 0 :(得分:0)
我认为答案可能是在这里使用此代码。但是,你的问题很糟糕,而且你显然没有尝试过。出于这个原因,我不打算发表评论,因为实际上,你应该自己解决。
class New(Exception):
pass
try:
word = input("Enter the word to guess: ")
knownLetters = []
for letter in word:
knownLetters.append("_")
guesses = []
param = " "
while True:
for letter in knownLetters:
if letter == "_":
exit = False
break
else:
exit = True
if exit:
raise New(" ")
for letter in guesses:
print(guesses)
print(knownLetters)
guess = str(input("Guess a letter {}".format(param)))
if len (guess) != 1:
param = "(Enter a single letter please!)"
continue
elif guess in guesses:
param = "({} already tried)".format(guess)
continue
elif guess in word:
guesses.append(guess)
for letterWord, letterKnown in zip ( word, range(len(word)) ):
if letterWord == guess:
knownLetters[letterKnown] = guess
except KeyboardInterrupt:
print("You have lost!")
except New:
print("You have won!")