异常实战2019-03-24

2019-03-24  本文已影响0人  swagsmile
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())
上一篇 下一篇

猜你喜欢

热点阅读