我的刽子手游戏中的while循环不起作用


answer = input("Type word here: ").lower()
word_amount = len(answer.split())
maximum_words = 1
while maximum_words != float(word_amount):
print("False input, 1 Word only!")
answer = input("Type word here: ").lower
word_amount = len(answer.split())

counter = 0
while counter != 20:
counter += 1
print("Can't see this!!!!!!")
guess_amount = 0
guess = input("Guess the word: ").lower()
while guess_amount != 9:
if answer == guess:
guess_amount = 9
print("You win!!!")
else:
print("Nope")
guess_amount += 1
guess = input("Guess again: ").lower()
if guess_amount == 9 and answer != guess:
print("You lose!!!")

这是我的刽子手游戏的全部代码,其中人1键入单词,然后人2有10次尝试猜测单词,除了while循环之外,一切都很好:

answer = input("Type word here: ").lower()
word_amount = len(answer.split())
maximum_words = 1
while maximum_words != float(word_amount):
print("False input, 1 Word only!")
answer = input("Type word here: ").lower
word_amount = len(answer.split())

当我运行游戏并输入多个单词时,游戏应该进入一个循环,并且应该继续要求只输入一个单词。但当我运行它时,输入一个以上的单词,然后输入一个单词(这应该会停止循环(,它说"split"不是一个定义的函数,我不知道为什么。如果有人能帮助我,我会很高兴。谢谢你:(

您在这一行中犯了一个错误。

answer = input("Type word here: ").lower

你忘了把括号放在下面。只需使用lower()而不是lower

您将获得所需的输出:

Type word here: hello how are you
False input, 1 Word only!
Type word here: hello fine
False input, 1 Word only!
Type word here: hello hi
False input, 1 Word only!
Type word here: 

最新更新