while循环仅执行一次

时间:2020-06-21 18:04:52

标签: python

我这里有一段代码应该循环播放,直到用户键入0为止。但是,它不会循环播放多次。

orderByChild

首先将temp变量设置为1。当我输入1重试时,它不会重试

 while temp==1:
        cachv = input("Enter CACH value: ")
        mmaxv = input("Enter MMAX value: ")
        inpuv = [cachv, mmaxv]
        inpuvd= np.reshape(inpuv, (-1, 2))
        test = clf.predict(inpuvd)
        if test == 0:
            print('The performance will be high')
        else:
            print('The performance will be low')
        temp = input('Retest? 1 for Y, 0 for N: ')
    print('done')

这是它的样子

2 个答案:

答案 0 :(得分:0)

函数input()返回一个字符串对象,这意味着您的temp变量变为字符串。 因此,您正在测试"1" == 1这是假的

您应按以下方式更新temp变量:

temp = int(input(" ... "))

答案 1 :(得分:0)

更改temp = input('Retest? 1 for Y, 0 for N: ')temp = int(input('Retest? 1 for Y, 0 for N: '))