ハングマンゲームの繰り返し入力(文字)を確認するにはどうすればよいですか?入力の繰り返しを確認する(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
感謝。
をあなたがこれまで持っていますか? –
へようこそ:あなたがこれまで持っているものを私たちに教えてください。 –
@MateenUlhaqコードを追加しました – Ned