如何为多个输入使用for循环

时间:2020-05-31 20:02:59

标签: python for-loop

这是我的代码,我想在其中应用for循环来检查最佳值结果。我想为num_ants = 1000应用for循环,所以我想测试值500,600、700、800,900的最佳值,并像这样对其他输入进行测试。

 num_ants = int(input("Please enter the number of ants (1000 recommended): "))
    if num_ants <= 0:
        quit("value entered for number of ants is non-positive")


min_cases_per_rule = int(input("Please enter the minimum number of cases per rule (10 recommended): "))
if min_cases_per_rule <= 0:
    quit("value entered for minimum number of cases per rule is non-positive")



max_uncovered_cases = int(input("Please enter the maximum number of uncovered cases in the training set (10 recommended): "))
if max_uncovered_cases < 0:
    quit("value entered for maximum number of uncovered cases is non-zero")




num_rules_converge = int(input("Please enter the number of rules used to test convergence of the ants (40 recommended): ")) #10
if num_rules_converge <= 0:
    quit("value entered for number of rules used to test convergence of the ants is non-positive")

1 个答案:

答案 0 :(得分:-1)

while True:  

        num_ants = int(input("Please enter the number of ants (1000 recommended): "))
        if num_ants <= 0:
            quit("value entered for number of ants is non-positive")


        min_cases_per_rule = int(input("Please enter the minimum number of cases per rule (10 recommended): "))
        if min_cases_per_rule <= 0:
            quit("value entered for minimum number of cases per rule is non-positive")


        max_uncovered_cases = int(input("Please enter the maximum number of uncovered cases in the training set (10 recommended): "))
        if max_uncovered_cases < 0:
            quit("value entered for maximum number of uncovered cases is non-zero")


        num_rules_converge = int(input("Please enter the number of rules used to test convergence of the ants (40 recommended): ")) #10
        if num_rules_converge <= 0:
            quit("value entered for number of rules used to test convergence of the ants is non-positive")

        # do your calculations and give results

        keep_going = input('Try another set of parameters? Type "no" to exit.')
        if keep_going == "no":
            break