使用这个:
while guess != answer and attempt >= 1
实际上,在第三次错误回答的情况下,您的代码没有将尝试变量更改为0,尝试变量保持为1,因此正在执行else块
您应该将循环条件更改为:
while guess != answer and attempt > 0:
while guess != answer and attempt => 1:
在你以前的版本中
while guess != answer and attempt > 1:
attempt=1 这就是为什么这种情况 if attempt == 0: 从来不是真的。
attempt=1
if attempt == 0: