Python returns wrong truth table for logical implication
<p><a href="http://i.stack.imgur.com/CChne.png" rel="nofollow"><img src="http://i.stack.imgur.com/CChne.png" alt="enter image description here"></a></p>

<p>I have implemented the above implication in Python but it does not return the expected results:</p>

<pre><code>  True       True None
  True      False None
 False       True True
 False      False None
</code></pre>

<p>My python code is:</p>

<pre><code>def implies(a,b):
    if a:
        return b
    else:True
    return
for p in (True, False):
    for q in (True, False):
        print("%10s %10s %s" %(p,q,implies((p or q) and (not p), q)))
</code></pre>

<p>I don't understand the contradiction here. None implies False doesn't it? And why not print True like it should?</p>

<pre><code>def implies(a,b):
    if a:
        return b
    else:True
    return
</code></pre>

<p>Your error is in the last two lines, if !a, you aren't returning a specific value, so the result is <code>None</code>.
You want:</p>

<pre><code>def implies(a,b):
    if a:
        return b
    else:
        return True
</code></pre>

python boolean-logic discrete-mathematics