Python multiplying all even numbers in a list
<p>I am working on this python code for my first programming class. Yesterday it partially worked but then I changed something and now it is only passing 1 test case. The goal is to multiply all even numbers in list "xs" and return 1 if there are no even numbers. What am I doing wrong and how can I fix it?</p>

<pre><code>def evens_product(xs):
    product = 2
    for i in xs:
        if i%2 == 0:
            product *= i
            return product

    else:
        return (1) 
</code></pre>

<p>Edit: Chepner's solution worked thank you to everyone who helped</p>

<p>This will be your answer:</p>

<pre><code>def evens_product(xs):
    product = 1
    for i in xs:
        if i%2 == 0:
            product *= i  
    return product
</code></pre>

<p>There is no need to <code>return</code> <code>1</code> since the product is already assigned <code>1</code>. 
Since you has the <code>return</code> inside the <code>for</code> loop it was returning the value after identifying the first even number. Hope it helped.</p>

python list numbers multiplying