Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Boolean Algebra solution in Clear category for Boolean Algebra by Seaclaid
ON = ("conjunction", "disjunction", "implication", "exclusive", "equivalence")
def boolean(x, y, op):
odp=0
if op=="conjunction":
odp= x and y
if op=="disjunction":
odp= x or y
if op=="implication":
odp= (not x) or y
if op=="exclusive":
odp= (x or y) and (not(x and y))
if op=="equivalence":
if x==y:
odp=1
else:
odp=0
print(x,y,op,odp)
if odp==1:
return True
else:
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert boolean(1, 0, "conjunction") == 0, "and"
assert boolean(1, 0, "disjunction") == 1, "or"
assert boolean(1, 1, "implication") == 1, "material"
assert boolean(0, 1, "exclusive") == 1, "xor"
assert boolean(0, 1, "equivalence") == 0, "same?"
assert boolean(0, 0, u"equivalence") == 1
Jan. 15, 2017