Errors and Exceptions.ipynb - Colab
Errors and Exceptions.ipynb - Colab
ipynb - Colab
1. Syntax errors
2. Logical errors (Exceptions)
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-2-5f312778a383> in <module>
3
4 # perform division with 0
----> 5 a = marks / 0
6 print(a)
if(a<3):
print("gfg")
https://colab.research.google.com/drive/1aQnLHmgBN8Ngwil96ej3POB4loPGDBii#printMode=true 1/3
12/10/24, 1:57 PM Errors and Exceptions.ipynb - Colab
code start
an error occurs
GeeksForGeeks
https://colab.research.google.com/drive/1aQnLHmgBN8Ngwil96ej3POB4loPGDBii#printMode=true 2/3
12/10/24, 1:57 PM Errors and Exceptions.ipynb - Colab
try:
if (age<18):
raise ValueError('Not Eligible for Age')
else:
print('Eligible')
except ValueError as val:
print(val)
Age of voter18
Eligible
try:
age = int(input("Input your age: "))
if age < 0:
print("Age cannot be negative.")
elif age>17:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
except ValueError:
print("Invalid input. Please input a valid age.")
https://colab.research.google.com/drive/1aQnLHmgBN8Ngwil96ej3POB4loPGDBii#printMode=true 3/3