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

CC BY-SA 3.0
4

1 Answer 1

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
CC BY-SA 3.0
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.