Modulus problems
<p>**I'm having problems using modulus for a simple evens and odds game.
**Whether for even or odd no matter what, the return is "Odd you win" or "Even you win" even when the player + cpu = 3 % 2 = 1 in function (even) I get a return of "Even you win."</p>

<pre><code>import random
even_odds = list(range(0,2))
play = random.choice(even_odds)
def selection():

which = input('Select O for odds and E for even: ').lower()

if which == 'o':
    odds()

elif which == 'e':
    evens()

def odds():
    even_odds 
    cpu = random.choice(even_odds)

    print("YOU CHOSE ODD")
    player = int(input("Choose a number between 0 and 2: "))
    print('cpu chose',cpu)
    print("You're choice plus the cpu's choice equals",player + cpu)
    print(" /n ...", player + cpu % 2 ) 
    if player + cpu % 2 != 0:
        print('Odd you win\n')
        selection()
    else:
        print('Even you lose!\n')
        selection()


def evens():
    even_odds 
    cpu = random.choice(even_odds)

    print("YOU CHOSE EVEN")
    player = int(input("Choose number between 0 and 2: "))
    print('cpu chose',cpu)
    print("You're choice plus the cpu's choice equals",player + cpu)
    if player + cpu % 2 == 0:
        print('Even you win! \n')
        selection()
    else:
        print('Odd you lose! \n')
        selection()
</code></pre>

<p>Output</p>

<pre><code>**Select O for odds and E for even: o
YOU CHOSE ODD
Choose a number between 0 and 2: 2
cpu chose 0
You're choice plus the cpu's choice equals 2
... 2
Odd you win**
</code></pre>

<p>You need to use parens:</p>

<pre><code>if (player + cpu) % 2 != 0:
</code></pre>

<p>You can see the difference with a simple example:</p>

<pre><code>In [10]:  5 + 5 % 2
Out[10]: 6

In [11]:  (5 + 5) % 2
Out[11]: 0
</code></pre>

<p><code>%</code> has a higher <a href="https://docs.python.org/2/reference/expressions.html#operator-precedence" rel="nofollow">precedence</a> than <code>+</code> so the modulo is performed first, then 5 is added to the result.</p>

<pre><code>In [12]:  5 % 2 
Out[12]: 1

In [13]:  5 % 2  + 5
Out[13]: 6
</code></pre>

python math modulus