使用python的两个命题的结果

时间:2013-02-24 08:49:30

标签: python

这是我第一次使用python的练习,我需要找到两个命题的连词,结合,排他或条件语句的值,以及这些命题的生物条件。 我真的是初学者,只需要知道我在哪里做错了这些命题的正确结果。 提前谢谢!

def conjunction(i,j): # conjunction i,j
    result = i + j
    return result

def disjunction(i,j): # dis-junction i,j
    result = i || result = j
    return result

def exclusive(i,j): # exclusive i,j
    result = j
    return result

def conditional(i,j): # conditional i,j
    if i = 0
    result = j
    if j =0
    result = i;
    return result

def biconditional (i,j): # biconditional i,j
    result = i = j && j = i
    return result

1 个答案:

答案 0 :(得分:1)

你走了:

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