10. Implementing real-time/technical applications using Exception handling. (divide by zero error, voter’s age validity, student mark range validation)
10. Implementing real-time/technical applications using Exception handling. (divide by zero
error, voter’s age validity, student mark range validation)
Program
a=int(input("Entre a="))
b=int(input("Entre b="))
try:
c = ((a+b) / (a-b))
#Raising Error
if a==b:
raise ZeroDivisionError
#Handling of error
except ZeroDivisionError:
print ("a/b result in 0")
else:
print (c)
Output
Enter
a=4
Enter b=4
a/b result in 0
Voter’s age validity
a=int(input("Enter your age"))
try:
c = a
#Raising Error
if c<18:
raise ValueError
#Handling of error
except ValueError:
print ("not eligible for voting - enter above 18")
else:
print (c)
Student mark range validation
a=int(input("Enter any marks"))
try:
c = a
#Raising Error
if c>0 and c>100:
raise ValueError
#Handling of error
except ValueError:
print ("not correct students mark range value btween 1-100")
else:
print (c)
Comments
Post a Comment