2 回答
TA贡献1834条经验 获得超8个赞
缩进是一种触动。尝试这个:
exact_word = "Guessing"
guess_kid = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False
while guess_kid != exact_word.casefold() and not(out_of_guesses):
if guess_count < guess_limit:
guess_kid = input("Enter another word : ")
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("Out of luck")
else:
print("you win")
使用循环/子句后跟踪缩进很重要。由于我们没有在while:循环之前缩进,我将前 5 行移动到完全左对齐。
因为while:循环开始一个循环,所以下一个子句if和相应的else子句缩进一个。这些子句下的子集文本再次缩进。
希望这可以帮助!
TA贡献1875条经验 获得超3个赞
exact_word = "Guessing"
guess_kid = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False
while guess_kid != exact_word.casefold() and not(out_of_guesses):
if guess_count < guess_limit:
guess_kid = input("Enter another word : ")
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("Out of luck")
else:
print("you win")
这对你有用。一旦在 中进行了一些更改,您需要检查条件out_of_guesses。
添加回答
举报