异常实战2019-03-24
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
网友评论