• 计算器代码


    代码比较low,有时间在更新。

    当时初学只是为了实现。

    #实现加减乘除以及括号优先级解析))
    
    import re
    
    s = "1-2*((60-30+(-40/5)*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))"
    # s = "1-2*((60-30-8*(9-3+146902+405))-(-4*3)/(16-3*2))"
    print(eval(s))
    
    
    def retr(str):
        try:
            str = str.replace("--", "+")
            str = str.replace("++", "+")
            str = str.replace("-+", "-")
            str = str.replace("+-", "-")
        except:
            pass
    
        ret = re.search("([^()]+)", str)
    
        a = ret.group()
        print(a)
        if ret == None:
            pass
        else:
            suan = ret.group()
            suan = suan.replace("(", "")
            suan = suan.replace(")", "")
        return suan,a
    
    # def th(str):
    
    def hf(str):
        a = str[:2]
        if not a.isdigit():
            if a == "-+" or a == "+-":
                str = str.replace(a, "-")
        return str
    
    def jjcc(str):
        nstr = hf(str)
        ret = re.search("(.*?d+)(D)(.*?d+)", nstr)
        # print(ret.group())
        a = ret.group(2)
        c = int(ret.group(1))
        b = int(ret.group(3))
        if a == "+":
            end = c + b
        if a == "-":
            end = c - b
        if a == "*":
            end = c * b
        if a == "/":
            end = c / b
        return end
    
    # print(jjcc(suan))
    # print(jjcc("-+6*-1"))
    
    
    # while True:
    #     suan, a = retr(s)[0],retr(s)[1]
    #     rep = str(jjcc(suan))
    #     s = s.replace(a, rep)
    #     print(s)
    
    suan, a = retr(s)[0], retr(s)[1]
    rep = str(jjcc(suan))
    s = s.replace(a, rep)
    # print(s)
    
    suan, a = retr(s)[0], retr(s)[1]
    rep = str(jjcc(suan))
    s = s.replace(a, rep)
    # print(s)
  • 相关阅读:
    性能测试流程
    性能测试关注的指标
    什么样的系统需要做性能测试
    python数据类型-列表
    python-数据类型-元组
    python自动化第二课
    python自动化第二课
    内存泄漏和内存溢出
    程序中必须知道的几种命名规范
    超级详细安装jmeter的教程(亲测)
  • 原文地址:https://www.cnblogs.com/GhostCatcg/p/8099632.html
Copyright © 2020-2023  润新知