当前这是我的代码,但是我不知道如何将生活概念整合到我的子手游戏中。当游戏结束(0岁)时,我希望游戏结束,即使他们在7次尝试后仍未弄清单词。
master = input("Enter a word: ")
print("\n"* 50 )
word = list(master)
length = len(word)
right = list("_" * length)
finished = False
while finished == False:
guess = input("Guess a letter!")
if guess not in master:
print("This letter is not in the word.")
for letter in word:
if letter == guess:
index = word.index(guess)
right[index] = guess
word[index] = "_"
print(right)
if list(master) == right:
print("You win!")
again = input("Again? y/n ")
if again == "y" or "Y":
master = input("Enter a word: ")
print("\n" * 50)
word = list(master)
length = len(word)
right = list("_" * length)
else:
finished = True
答案 0 :(得分:0)
您必须使用允许的错误尝试次数来初始化变量,并在每次输入错误时将其递减1。最后,在继续循环之前检查尝试次数是否已完成(即0)。
ValueError Traceback (most recent call last)
<ipython-input-21-bfc977603445> in <module>()
5 else:
6 pass
----> 7 animal_crackers('Levelheaded Llama')
<ipython-input-21-bfc977603445> in animal_crackers(text)
1 def animal_crackers(text):
----> 2 for [word1, word2] in text.split():
3 if word1[0]==word2[0]:
4 return true
5 else:
ValueError: too many values to unpack (expected 2)