Skip to content
Advertisement

Change value every nth iteration python

How can I change a value inside a loop every 10th iteration?

Say I have a list with 30 properties

JavaScript

I would like to change the value of x by a factor of 10 every 10th time.

Desired outcome

JavaScript

**

Advertisement

Answer

Modulo is a nice way of doing that:

JavaScript

Edit: you should probably initialize x outside the loop.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement