a = 'a'
b = 1
try :
af = float ( a )
bf = float ( b )
c = af / bf
except TypeError :
print ( 'They are not float' )
except ZeroDivisionError :
print ( 'Can not be divided by ZERO' )
else :
cf = c ** (1 / 3)
print ( cf )
因为发生的异常类型是ValueError,而你的except语句没有捕获这种类型的异常
a = 'a'
b = 1
try :
af = float ( a )
bf = float ( b )
c = af / bf
except TypeError :
print ( 'They are not float' )
except ZeroDivisionError :
print ( 'Can not be divided by ZERO' )
except ValueError:
print ('ValueError')
else :
cf = c ** (1 / 3)
print ( cf )