Uploaded by Mohamed Afzal Akthar

exception programs

advertisement
# Method 1
a=int(input('Enter the dividend'))
b=int(input('Enter the divisor'))
try:
print(a/b)
except ZeroDivisionError:
print("You can't divide by zero!")
# Method 2
a=int(input('Enter the dividend'))
b=int(input('Enter the divisor'))
try:
print(a/b)
print(a+'1')
except ZeroDivisionError:
print("You can't divide by zero!")
except TypeError:
print('Type error')
else:
print('...')
# Method 3
a=int(input('Enter the dividend'))
b=int(input('Enter the divisor'))
try:
print(a/b)
print(a+'1')
print(ab)
print(o)
except ZeroDivisionError:
print("You can't divide by zero!")
except TypeError:
print('Type error')
except:
print('Unexpected Error')
# Method 4
try:
a=int(input('Enter the dividend'))
b=int(input('Enter the divisor'))
print(a/b)
except ZeroDivisionError:
print("You can't divide by zero!")
except TypeError:
print('Type error')
finally: print('done')
Download