Need help multiplying positive numbers in a list by 3, and leaving other numbers unmodified
<p>My goal is to multiply all positive numbers in a list by 3. I think I've almost got the solution but I'm not sure what is causing it not to work. It currently just returns back the original numbers and does not multiply any numbers by 3.</p>

<pre><code>def triple_positives(xs):
    List = []
    product = 3
    for i in range (len(List)):
        if List[i] &gt;= 0:
            product *= i
        List.append(xs[i])
    return xs
</code></pre>

<p>In your code, there are multiple issues. Below is the updated version of it with fixes:</p>

<pre><code>&gt;&gt;&gt; def triple_positives(xs):
...     List = []
...     product = 3
...     for i in range (len(xs)):
...         if xs[i] &gt;= 0:
...             List.append(xs[i]*3)
...         else:
...             List.append(xs[i])
...     return List
...
&gt;&gt;&gt; my_list = [1, 2, -1, 5, -2]
&gt;&gt;&gt; triple_positives(my_list)
[3, 6, -1, 15, -2]
</code></pre>

<p>Alternatively, you may achieve this using List Comprehension as:</p>

<pre><code>&gt;&gt;&gt; [item * 3 if item &gt; 0 else item for item in my_list]
[3, 6, -1, 15, -2]
</code></pre>

python list numbers multiplying