首页 > 解决方案 > 试图找出我的代码是如何出错的

问题描述

我是一个学习Python的初学者,写了以下代码。为了控制循环流程,我尝试使用变量“test”,但循环从未停止过。欣赏是否有任何想法。

test=False
while test==False:
    a=input("Please enter an even number to make test True: ")
    if int(a)%2==0:
        test==True
        print("test is now True")
    else:
        print("Please try again!")

标签: pythonloops

解决方案


test=False

while test is False:
    a=input("Please enter an even number to make test True: ")
    if int(a) %2 == 0:
        test = True
        print("test is now True")
    else:
        print("Please try again!")

修正了 test == true,应该是 test = true :) 学习愉快


推荐阅读