如何檢查hang子手遊戲的重複輸入(字母)?檢查重複輸入(Python)
例子:
字是蘋果
輸入猜一個字母:一個
輸出做得很好!
然後猜一個字
輸入猜一個字母:一個
輸出應該是你已經猜到那封信。
我的代碼:
def checkValidGuess():
word = getHiddenWord()
lives = 10
num = ["1","2","3","4","5","6","7","8","9",]
#guessed = ''
while lives != 0 and word:
print("\nYou have", lives,"guesses left")
letter = input("Guess a letter or enter '0' to guess the word: ")
if letter.lower() in word:
print("Well done!", letter, "is in my word!")
lives -= 1
elif len(letter)>1:
print("You can only guess one letter at a time!")
print("Try again!")
elif letter in num:
print("You can only input letter a - z!")
print("Try again!")
#elif letter in guessed:
#print("repeat")
elif letter == "0":
wword = input("What is the word?").lower()
if wword == word:
print("Well done! You got the word correct!")
break
else:
print("Uh oh! That is not the word!")
lives -= 1
#elif letter == "":
#print("Uh oh! the letter you entered is not in my word.")
#print("Try again!")
else:
print("Uh oh! the letter you entered is not in my word.")
print("Try again!")
lives -= 1
感謝。
你有什麼這麼遠嗎? –
歡迎來到SO:向我們展示你到目前爲止所擁有的。 –
添加了代碼@MateenUlhaq – Ned