ArithmeticError is simply an error that occurs during numeric calculations.
ArithmeticError types in Python include:
These errors are all capable of crashing a code in Python. It is essential to catch an error because you do not want your code to crash as a result of incorrect input from you or a user.
The program below will reveal what error will arise from our code.
arithmetic = 5/0 print(arithmetic)
You can see that the code above returns an error output that reads as follows:
ZeroDivisionError: division by zero
This is a type of
Mathematically, dividing an integer by zero is wrong, and that is the reason why Python crashes the program and returns an error message.
Now, let us see how we can catch any of these errors in our code.
try: arithmetic = 5/0 print(arithmetic) except ArithmeticError: print('You have just made an Arithmetic error')
exceptblock to help us check for errors in our line of codes.
exceptto check for an
ArithmeticErrorand complete the block.
ArithmeticErrorin our code, we have previously told Python to return a text output instead of crashing our program.
View all Courses