Conditional addition of different values to an array using python
<p>I want to add 10 if <code>x &lt; 50</code>, 20 if <code>50 &lt;= x &lt; 100</code>, 30 if <code>100 &lt;= x &lt; 150</code>, and 40 for <code>150 &lt;= x &lt; 200</code>. How can I solve this problem? In my array <code>arr</code> I have more than 300 data element. Thanks in advance for your kind co-operation.   </p>

<pre><code>arr =[10,20,30,40,50,60,70,80,90,100,120,130,140,150,160,170,180,190,200]
</code></pre>

<p>It seems a little bit like a homework exercise?
I'd explicitly split out the modifications you need to make so it's easy to see what it's doing. Please note: I did not input ALL your rules, just some, so you can see how you could extend it.</p>

<pre><code>x=[10,20,30,40,50,60,70,80,90,100,120,130,140,150,160,170,180,190,200]
for value in x:
     oldvalue = value
     if value  &lt; 50:
         value += 10
     elif value &lt; 100:
         value += 20
     else:
         value += 30
     print("%i =&gt; %i" % (oldvalue, value))
</code></pre>

<p>this prints:</p>

<pre><code>10 =&gt; 20
20 =&gt; 30
30 =&gt; 40
40 =&gt; 50
50 =&gt; 70
60 =&gt; 80
70 =&gt; 90
80 =&gt; 100
....
</code></pre>

python arrays conditional add