OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

if statement is executed while condition is false. with modulo [duplicate]

  • Thread starter Thread starter Axel
  • Start date Start date
A

Axel

Guest
i am working an a set of data that roughly repeats itself every 34 data points. however i wish to modify every N-th value. but in every repetion of the data set. the amount of data sets can vary.

i figured the modulo would be perfect for this. and so i made the following if statement tree:

Code:
data_list = []
datastring = "".join(data_list)
csv = datastring.split(",")
print(csv)
counter= 1
value1 = 0
value2 = 0
value3 = 0
value4 = 0

for item in csv:
    print(counter%34)
    if counter%34 == 8 or 9 or 14 or 15:
        item = 0.00
        print (item)  
    elif counter % 34 == 18:
        value1 = item
        print(item)
    elif counter % 34 == 19:
        value2 = item
        print(item)
    elif counter % 34 == 20:
        item = value1
        print(item)
    elif counter % 34 == 21:
        item = value2
        print(item)
    elif counter % 34 == 23:
        value3 = item
        print(item)
    elif counter % 34 == 24:
        value4 = item
        print(item)
    elif counter % 34 == 25:
        item = value3
        print(item)
    elif counter % 34 == 26:
        item = value4
        print(item)
    else:    
        print(item)


    counter = counter + 1

a minor problem in this for loop is that i dont know how to access the iteration that is why im using a counter which works, but does not feel like clean code.

my mayor problem is that it attributes every iteration to the first if statement. while the respective value of the counter does loop around as expected at 34.

im at a loss how to solve this.

any recomdations would be apreciated
<p>i am working an a set of data that roughly repeats itself every 34 data points. however i wish to modify every N-th value. but in every repetion of the data set. the amount of data sets can vary.</p>
<p>i figured the modulo would be perfect for this. and so i made the following if statement tree:</p>
<pre><code>data_list = []
datastring = "".join(data_list)
csv = datastring.split(",")
print(csv)
counter= 1
value1 = 0
value2 = 0
value3 = 0
value4 = 0

for item in csv:
print(counter%34)
if counter%34 == 8 or 9 or 14 or 15:
item = 0.00
print (item)
elif counter % 34 == 18:
value1 = item
print(item)
elif counter % 34 == 19:
value2 = item
print(item)
elif counter % 34 == 20:
item = value1
print(item)
elif counter % 34 == 21:
item = value2
print(item)
elif counter % 34 == 23:
value3 = item
print(item)
elif counter % 34 == 24:
value4 = item
print(item)
elif counter % 34 == 25:
item = value3
print(item)
elif counter % 34 == 26:
item = value4
print(item)
else:
print(item)


counter = counter + 1
</code></pre>
<p>a minor problem in this for loop is that i dont know how to access the iteration that is why im using a counter which works, but does not feel like clean code.</p>
<p>my mayor problem is that it attributes every iteration to the first if statement. while the respective value of the counter does loop around as expected at 34.</p>
<p>im at a loss how to solve this.</p>
<p>any recomdations would be apreciated</p>
 
Top