私信  •  关注

Stonecutter

Stonecutter 最近创建的主题
Stonecutter 最近回复了
5 年前
回复了 Stonecutter 创建的主题 » 如果返回true,则使用相同的字典值重复python函数

我不确定我是否正确理解你的问题,但是如果你想在一个特定的值上达到真值,你可以通过一个“for”循环来实现:

my_list=[v1, v2, v3]
for i in my_list:
    if i <= crit_value:
        #Here you can call the function
        print('False')
    else:
        print('True')
        # Next line only when you want to quit the loop here
        break

对于本例,只要列表中的值较低或与临界值相同,就将停留在for循环中;如果高于临界值,则将退出循环并打印“true”。


编辑:

由于您的意思是值总是在变化,您可以这样做:

my_list=[v1, v2, v3]
# Now you use indices starting from zero until the number of elements in the list 
for i in range(len(my_list)):
    # I will set the number of maximum trys to 1000, this can be changed
    for j in range(1000):
        if my_list[i] <= crit_value:
            # Here you would need to reload my_list
            print('False')
        else:
            print('True')
            # To give you the actual value
            print(my_list[i])
            break