answer = 5
guess = int(input('Please make a wild number guess: '))
count = 1
while guess != answer:
count += 1
int(input('wrong. Please make another guess: '))
print(f"this is your {count} attempt")
if guess == answer:
break
print('Correct!!!')
我没有得到答案我以为在我打了5之后。在输入正确答案后,我仍然被困在while循环中。
是错误的。请再猜一猜这是你的第6次尝试
因为您没有更新"guess"在while循环中,将其更改为
guess = int(input('wrong. Please make another guess: '))
正如@Soulfly提到的,你需要更新guess
。
另外,我建议修改:
if guess == answer:
break
print('Correct!!!')
if guess == answer:
print('Correct!!!')
break
因此在输出print语句之前循环不会中断。