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

Popular posts from this blog

7. Implementing programs using Strings. (reverse, palindrome, character count, replacing characters)

1. Identification and solving of simple real life or scientific or technical problems, and developing flow charts for the same.

G3151-Problem Solving and Python Programming (2021 Regulations Anna University,Chennai)