Py学习  »  user9113784  »  全部回复
回复总数  2
5 年前
回复了 user9113784 创建的主题 » Python中数字的处理

使用这个:

while guess != answer and attempt >= 1

实际上,在第三次错误回答的情况下,您的代码没有将尝试变量更改为0,尝试变量保持为1,因此正在执行else块

5 年前
回复了 user9113784 创建的主题 » Python中数字的处理

您应该将循环条件更改为:

while guess != answer and attempt > 0:

while guess != answer and attempt => 1:

在你以前的版本中

while guess != answer and attempt > 1:

attempt=1 这就是为什么这种情况 if attempt == 0: 从来不是真的。