-3

enter image description here

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

  True       True None
  True      False None
 False       True True
 False      False None

My python code is:

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)))

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

m00am
  • 5,910
  • 11
  • 53
  • 69
Sarah cartenz
  • 1,313
  • 2
  • 14
  • 37

1 Answers1

2
def implies(a,b):
    if a:
        return b
    else:True
    return

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

def implies(a,b):
    if a:
        return b
    else:
        return True
Juri Robl
  • 5,614
  • 2
  • 29
  • 46