干得好:
def conjunction(i,j): # conjunction i,j
return (i and j)
def disjunction(i,j): # dis-junction i,j
return (i or j)
def exclusive(i,j): # exclusive i,j
return (i != j)
def conditional(i,j): # conditional i,j
return j if i else True
def biconditional (i,j): # biconditional i,j
return (i == j)
output = [[],[],[],[],[]]
titles = ["Conjunction", "Disjunction", "Exclusive", "Conditional", "Biconditional"]
for f1 in [True, False]:
for f2 in [True, False]:
output[0].append('{0:8s} | {1:8s} | {2:8s}'.format(str(f1), str(f2), str(conjunction(f1, f2))))
output[1].append('{0:8s} | {1:8s} | {2:8s}'.format(str(f1), str(f2), str(disjunction(f1, f2))))
output[2].append('{0:8s} | {1:8s} | {2:8s}'.format(str(f1), str(f2), str(exclusive(f1, f2))))
output[3].append('{0:8s} | {1:8s} | {2:8s}'.format(str(f1), str(f2), str(conditional(f1, f2))))
output[4].append('{0:8s} | {1:8s} | {2:8s}'.format(str(f1), str(f2), str(biconditional(f1, f2))))
for i in range(5):
print "=" * 30
print titles[i]
print "-" * 30
print "\n".join(output[i])
print "-" * 30
输出
==============================
Conjunction
------------------------------
True | True | True
True | False | False
False | True | False
False | False | False
------------------------------
==============================
Disjunction
------------------------------
True | True | True
True | False | True
False | True | True
False | False | False
------------------------------
==============================
Exclusive
------------------------------
True | True | False
True | False | True
False | True | True
False | False | False
------------------------------
==============================
Conditional
------------------------------
True | True | True
True | False | False
False | True | True
False | False | True
------------------------------
==============================
Biconditional
------------------------------
True | True | True
True | False | False
False | True | False
False | False | True
------------------------------