samedi 17 octobre 2020

Nested ranges only working for the last range

Absolute beginner here so I apologize if some terms are incorrectly used. I'm trying to run several ranges at the same time until one of them reaches the target. I tried nesting them but what happened is that only the last range was working towards the target while the others were stuck at 1. To clarify I wanted x1 to print out 3,6,9,12.., x2 to print out 2,4,6,8.. and x3 to print out 1,2,3,4... instead x1 and x2 printed only 1,1,1,1... and only x3 was printing correctly as 1,2,3,4,...

range1 = (range(0, 100000000000000000000, 3))
range2 = (range(0, 100000000000000000000, 2))
range3 = (range(0, 100000000000000000000, 1))
for x1 in range1:
    for x2 in range2:
        for x3 in range3:

            if x1 == 1358445000:
                print ("x1=", x1)
                break
            if x2 == 1358445000:
                print ("x2=", x2)
                break
            if x3 == 1358445000:
                print ("x3=", x3)
                break

            else:
                print (x1)
                print (x2)
                print (x3)

Aucun commentaire:

Enregistrer un commentaire