• 简易计算机python实现


    def Calculation():
        number_str=""
        print "欢迎您使用光荣之路计算机"
        while 1:
            print "退出系统请按回车键"
            operation=raw_input("请输入您的下一步操作: ")
            if operation=="":
                operation=raw_input("您确定要退出系统吗,确定请按数字'1': ")
                if operation=="1":
                    print "退出成功"
                    break
            elif operation in ["+","-","*","/","//"]:
                if len(number_str)==0:
                    number_str+=operation
                else:
                    if number_str[-1] in ["+","-","*","/","//"]:
                        print "您已经连续输入两次计算符号,请您重新输入要计算的数字"
                    else:
                        number_str+=operation
            elif operation.isdigit():
                if len(number_str)==0:
                    number_str+=operation
                else:
                    if number_str[-1].isdigit():
                        print "您已经连续输入两次计算符号,请您重新输入要计算的数字"
                    else:
                        number_str+=operation
            elif operation=="=":
                if number_str=="":
                    print "您要计算得内容为空,请输入内容"
                elif number_str[-1] in ["+","-","*","/","//"]:
                    print "您要计算的内容最后内容为空,请您输入计算内容"
                else:
                    try:
                        if number_str[0].isdigit():
                            print number_str+"计算结果为:"+str(eval_r(number_str))
                        else:
                            print "0"+number_str+"计算结果为:"+str(eval_r(number_str))
                    except Exception:
                        print number_str+"计算过程中出现错误:"+e.message

            else:
                operation=raw_input("您输入有误,请重新输入: ")
  • 相关阅读:
    CF1236B Alice and the List of Presents |数学
    luogu P1832 A+B Problem |背包
    CF832D Misha, Grisha and Underground |LCA
    bzoj1709[Usaco2007 Oct]Super Paintball超级弹珠*
    bzoj3314[Usaco2013 Nov]Crowded Cows*
    bzoj4300绝世好题
    bzoj2101[Usaco2010 Dec]Treasure Chest 藏宝箱*
    bzoj3437小P的牧场
    bzoj2016[Usaco2010]Chocolate Eating*
    bzoj2015[Usaco2010 Feb]Chocolate Giving*
  • 原文地址:https://www.cnblogs.com/zhangtebie/p/11185926.html
Copyright © 2020-2023  润新知