Python "equal to" and "not equal to" : <p>I was doing a practice question and couldn't figure out what I was doing wrong. Seems I was a little confused about how <code>or</code> should work.</p>

<p>I'll pass both a range of numbers from 13 - 19:</p>

<pre><code>for i in range(13,20):
    func(i)
</code></pre>

<blockquote>
  <p>Function 1</p>
</blockquote>

<pre><code>def func(n):
    if n == 15 or n == 16:
        pass
    else:
        n = 0
</code></pre>

<blockquote>
  <p>Result 1</p>
</blockquote>

<pre><code>0
0
15
16
0
0
0
</code></pre>

<p>So if n is equal to 15 or if <code>n</code> is equal to 16, pass. Anything else, make it 0. Makes sense.</p>

<blockquote>
  <p>Function 2</p>
</blockquote>

<pre><code>def func(n):
    if n != 15 and n != 16:
        n = 0
    else:
        pass
</code></pre>

<blockquote>
  <p>Result 2</p>
</blockquote>

<pre><code>0
0
15
16
0
0
0
</code></pre>

<p>If <code>n</code> is not equal to 15 or 16, make it 0. Else, pass. Again, makes sense.</p>

<p>Here's where I get a little unstuck:</p>

<blockquote>
  <p>Function 3</p>
</blockquote>

<pre><code>def func(n):
    if n == 15 and n == 16:
        pass
    else:
        n = 0
</code></pre>

<blockquote>
  <p>Result 3</p>
</blockquote>

<pre><code>0
0
0
0
0
0
0
</code></pre>

<p><em>I think</em> the result is due to both conditions for <code>n</code> needing to be met; if is equal both 15 <strong>and</strong> 16, pass, else make it zero. I get that.</p>

<blockquote>
  <p>Function 4</p>
</blockquote>

<pre><code>def func(n):
    if n != 15 or n != 16:
        n = 0
    else:
        pass
</code></pre>

<blockquote>
  <p>Result 4</p>
</blockquote>

<pre><code>0
0
0
0
0
0
0
</code></pre>

<p>If <code>n</code> is not equal 15 or <code>n</code> is not equal to 16, then it should be zero. </p>

<p><em>I think</em> this means <code>or</code> somehow works the same way as <code>and</code> in that both conditions must be met, but was wondering if someone more knowledgeable could explain?</p>
