【发布时间】:2017-06-14 10:15:19
【问题描述】:
如何检查刽子手游戏的重复输入(字母)?
例子:
单词是苹果
输入是猜一个字母:a
输出做得很好!
然后猜下一个单词
输入是猜一个字母:a
输出应该是你已经猜到了那个字母。
我的代码:
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
-
代码添加@ShawnMehan
标签: python python-3.x input