Boolean Python0.5交互界面
本帖最后由 KeyError 于 2023-3-31 23:10 编辑效果:
> AND[ 1 0 ]
0
> AND[ OR[ 1 0 ] NOT[ 0 ] ]
1
>
代码:
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 == "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.'''
C = 0
jilu = []
go, end = 0, 0
x = 0
up = ""
for i in dm:
if up == "AND" and len(jilu) >= 2:
num = All.AND(jilu, jilu)
elif up == "OR" and len(jilu) >= 2:
num = All.OR(jilu, jilu)
elif up == "NOT" and len(jilu) >= 1:
num = All.NOT(jilu)
if i == "AND[":
jilu = []
C += 1
go = x
x += 1
up = "AND"
continue
elif i == "OR[":
jilu = []
C += 1
go = x
x += 1
up = "OR"
continue
elif i == "NOT[":
jilu = []
C += 1
go = x
x += 1
up = "NOT"
continue
elif i == "]":
if (len(jilu) >= 2 and C > 0) or (len(jilu) >= 1 and up == "NOT" and C > 0):
C -= 1
end = x
del dm
jilu = []
dm.insert(go, str(num))
if len(dm) == 1:
return dm + "\n"
else:
return evalnum(dm)
else:
error = "]["
raise SyntaxError("Syantax")
elif i == "1":
jilu.append(1)
elif i == "0":
jilu.append(0)
else:
error = "???"
raise NameError("Name")
x += 1
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()
输入HELP, 翻译输出, 有惊喜! HELP yubi 奥利给 1 功能要是再多一点就好了 育碧飞来 欢迎使用布尔Python 0.5,布尔Python是由一个白痴在2023年开发的。布尔Python是一个相当无用的二进制计算器,可以帮助您在二进制之间进行操作。但是,这些功能已经在Python中可用,所以您完全可以不安装布尔Python,因为它太无用了。
如何使用:
1.AND
AND
"AND "返回x1和x2。例如,"AND "返回0。
2.OR
OR
"OR "返回x1或x2。例如,"OR "返回1。
3.NOT
NOT
"NOT "返回非x1。例如,"NOT "返回0。 支持~ 静待高手解决
..厉害 鱼币 看看 鱼币 再来 1 {:5_109:} sfqxx 发表于 2023-3-31 23:46
功能要是再多一点就好了
是的 KeyError 发表于 2023-4-1 22:07
是的
{:10_264:}