Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add count until certain value then reset to zero python

I am trying to change the value of x depending on the length of my list

How can x count up by 5 through each iteration and then back to 0 after the 10th round?

list = {"one", "two".....fifty} #example shortened 
listLen = len(list) # 50

for i in range (0, listLen) # 0 - 49

    x = ??? # +5 max 45 
    
    ops.update(location=x)

Desired outcome:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

0. x = 0
1. x = 5
2. x = 10
...
9. x = 45

10. x = 0
11. x = 5
12. x = 10
...
19. x = 45
...



(0,5,10,15,20,25,30,25,40,45,0,5,10,15,20,25,30,25,40,45            
 0,5,10,15,20,25,30,25,40,45,0,5,10,15,20,25,30,25,40,45
 0,5,10,15,20,25,30,25,40,45) 

>Solution :

Try this:

ans = []
for i in range (0, listLen): # 0 - 49
    x += 5
    ans.append(x)
    if i % 9 == 0:
        x = 0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading