美文网首页
异常实战2019-03-24

异常实战2019-03-24

作者: swagsmile | 来源:发表于2019-03-24 20:22 被阅读0次
def main():
    a=input("please input the first number:")
    b=input("please input the second number:")
    op=input("please input the operator:")
    
    try:
        a=int(a)      
    except ValueError:
        print("please input the correct first number:")
        a=int(input())
        
    try:
        b=int(b)
    except ValueError:
        print("please input the correct second number:")
        b=int(input())
        
    result=SimpleCalculator(a,b,op)
    
    return result

def SimpleCalculator(a,b,op):
        if op == "+":
            result=a+b
            return result
        elif op == "-":
            result=a-b
            return result
        elif op=="*":
            result=a*b
            return result
        elif op == "/":
            try:
                result=a/b
            except ZeroDivisionError:
                print("the num of b can't be zero!!")
print(main())

相关文章

网友评论

      本文标题:异常实战2019-03-24

      本文链接:https://www.haomeiwen.com/subject/sdlpvqtx.html