error = 0
class All:
def AND(x1, x2):
return int(x1 and x2)
def OR(x1, x2):
return int(x1 or x2)
def NOT(x1):
return int(not x1)
def evalnum(dm):
global error
if dm[0] == "HELP":
return '''Welcome to Boolean Python 0.5, Boolean Python was developed by an idiot in 2023.
The Boolean Python is a pretty useless binary calculator that helps you compute operations between binaries.
But these features are already available in Python, so you could have done without installing Boolean Python, as it's too useless.
How to use:
1.AND
AND[ x1 x2 ]
The "AND[ x1 x2 ]" returns x1 and x2.For example, "AND[ 1 0 ]" returns 0.
2.OR
OR[ x1 x2 ]
The "OR[ x1 x2 ]" returns x1 or x2.For example, "OR[ 0 1 ]" returns 1.
3.NOT
NOT[ x1 ]
The "NOT[ x1 ]" returns not x1.For example, "NOT[ 1 ]" returns 0.'''
else:
return eval(dm.lower().replace('[', '(')
def run(dm):
if dm.isspace() or dm == "":
print("SyntaxError: space input")
else:
try:
x = dm.split(" ")
print_yesno = False
num = evalnum(x)
print(num, end="")
except Exception as e:
if error == "[]":
print("SyntaxError: There's no ] corresponding to the [")
elif error == "][":
print("SyntaxError: There's no [ corresponding to the ]")
elif error == "???":
print("NameError: here's not BIF")
def main():
while True:
x = input("> ")
run(x)
main()
给你省下一大截! |