zoukankan      html  css  js  c++  java
  • 简易计算机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("您输入有误,请重新输入: ")
  • 相关阅读:
    css文档流
    gitolite搭建
    Packets out of order. Expected 1 received 27...
    前端常见跨域解决方案
    跨时代的分布式数据库 – 阿里云DRDS详解
    Redis持久化机制
    redis实现消息队列
    队列
    ide-helper
    Bitmap 位操作相关
  • 原文地址:https://www.cnblogs.com/zhangtebie/p/11185926.html
Copyright © 2011-2022 走看看