Last active
October 12, 2023 06:11
-
-
Save ivabus/d95ac62ffee85b7b058effc573760ae9 to your computer and use it in GitHub Desktop.
Print truth table for given expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iterate(l, ost): | |
if ost == 0: return l | |
newL = [] | |
for i in l: | |
for k in "01": newL.append(i + k) | |
return iterate(newL, ost - 1) | |
func = input("Input function (in eval format): ") | |
variables = [] | |
for i in func: | |
if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and not i in variables: variables.append(i) | |
iterList = iterate([""], len(variables)) | |
print(*variables, sep="", end=" F\n") | |
for i in iterList: | |
currFunc = func | |
for k in range(len(variables)): currFunc = currFunc.replace(variables[k], i[k]) | |
print(i, str(eval(currFunc)).replace("True", "1").replace("False", "0")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
оформление 10/10, не переделывай