how do you add values from a list separately if one variable has two possible outcomes
<p>This assignment calls another function:</p>

<pre><code>def getPoints(n):
    n = (n-1) % 13 + 1
    if n == 1:
        return [1] + [11]
    if 2 &lt;= n &lt;= 10:
        return [n]
    if 11 &lt;= n &lt;= 13:
        return [10] 
</code></pre>

<p>So my assignment wants me to add the sum of all possible points from numbers from a list of 52 numbers. This is my code so far.</p>

<pre><code>def getPointTotal(aList):
    points = []
    for i in aList:
        points += getPoints(i)
        total = sum(points)   
    return aList, points, total
</code></pre>

<p>However the issue is that the integer 1 has two possible point values, 1 or 11. When I do the sum of the points it does everything correctly, but it adds 1 and 11 together whereas I need it to compute the sum if the integer is 1 and if the integer is 11.</p>

<p>So for example:</p>

<pre><code>&gt;&gt;&gt;getPointTotal([1,26, 12]) # 10-13 are worth 10 points( and every 13th number that equates to 10-13 using n % 13.
&gt;&gt;&gt;[21,31] # 21 if the value is 1, 31 if the value is 11.
</code></pre>

<p>Another example:</p>

<pre><code>&gt;&gt;&gt;getPointTotal([1,14]) # 14 is just 14 % 13 = 1 so, 1 and 1.
&gt;&gt;&gt;[2, 12, 22] # 1+1=2, 1+11=12, 11+11=22
</code></pre>

<p>My output is:</p>

<pre><code>&gt;&gt;&gt;getPointTotal([1,14])
&gt;&gt;&gt;[24] #It's adding all of the numbers 1+1+11+11 = 24.
</code></pre>

<p>So my question is, is how do I make it add the value 1 separately from the value 11 and vice versa. So that way when I do have 1 it would add all the values and 1 or it would add all the values and 11.</p>

<p>You make a mistake in storing all the values returned from <code>getPoints()</code>. You should store only the possible totals for the points returned so far. You can store all those in a set, and update them with the all the possible values returned from <code>getPoints()</code>. A set will automatically remove duplicate scores, such as 1+11 and 11+1. You can change the set to a sorted list at the end. Here is my code:</p>

<pre><code>def getPointTotal(aList):
    totals = {0}
    for i in aList:
        totals = {p + t for p in getPoints(i) for t in totals}
    return sorted(list(totals))
</code></pre>

<p>I get these results:</p>

<pre><code>&gt;&gt;&gt; print(getPointTotal([1,26, 12]))
[21, 31]
&gt;&gt;&gt; print(getPointTotal([1,14]))
[2, 12, 22]
</code></pre>

python list python-3.x sum