编写一个可以接受ZeroDivisionError和TypeError的错误类型,并且并且定义变量e用于接收具体错误信息。
try:
a = 10
b = input()
if b.isdigit():
b = int(b)
c = (a+b)/0
except TypeError as e:
print("TypeError!")
print(e)
except ZeroDivisionError as e:
print("ZeroDivisionError!")
print(e)
应该可以用 try ... except Exception as e: ... 让变量 e 接收拦截的错误提示字符串的吧。