vendredi 4 mai 2018

how to iterate one value twice in for loop (Python)

I am having a problem in really simple program. My problem is that i lose value (y = 50 or 100 or 150) because at that time first condition is not valid. so how can i repeat loop for let say y = 50. (i don't want to use '=' e.g y< = (50+increment) because this is just a dummy program.

thanks

increment = 0
b = 1
var = 0
for y in range(1,1000):
    if y>= increment and y< (50+increment):
        print(f'{y}  in List {b}')

    else:
        var = y
        increment += 50
        b+=1

Aucun commentaire:

Enregistrer un commentaire