KeyError 发表于 2023-3-31 23:09:04

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


KeyError 发表于 2023-3-31 23:10:16

输入HELP, 翻译输出, 有惊喜!

hornwong 发表于 2023-3-31 23:26:49

HELP

sfqxx 发表于 2023-3-31 23:31:16

yubi

sfqxx 发表于 2023-3-31 23:33:02

奥利给

sfqxx 发表于 2023-3-31 23:45:49

1

sfqxx 发表于 2023-3-31 23:46:34

功能要是再多一点就好了

歌者文明清理员 发表于 2023-4-1 07:25:50

育碧飞来

歌者文明清理员 发表于 2023-4-1 07:28:56

欢迎使用布尔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。

学习编程中的Ben 发表于 2023-4-1 08:24:10

支持~

鱼与熊掌可兼得 发表于 2023-4-1 16:32:15

静待高手解决

start1 发表于 2023-4-1 16:33:49

..厉害

start1 发表于 2023-4-1 16:36:07

鱼币

平凡之路1314 发表于 2023-4-1 16:57:25

看看

平凡之路1314 发表于 2023-4-1 16:58:23

鱼币

平凡之路1314 发表于 2023-4-1 16:59:02

再来

2399746388 发表于 2023-4-1 17:04:12

1

Mike_python小 发表于 2023-4-1 20:52:37

{:5_109:}

KeyError 发表于 2023-4-1 22:07:49

sfqxx 发表于 2023-3-31 23:46
功能要是再多一点就好了

是的

sfqxx 发表于 2023-4-1 22:24:38

KeyError 发表于 2023-4-1 22:07
是的

{:10_264:}
页: [1] 2 3
查看完整版本: Boolean Python0.5交互界面