Write a python program to create a user-defined exception named “ShortInputException” that raises when the input text length is less than 3.

 class ShortInputException(Exception):

    def __init__(self,length):

        Exception(self)

        self.len=length

string=input("Enter The String")

length=len(string)

try:

    if length<3:

        raise ShortInputException(length)

except ShortInputException as s:

    print("The Length of String Is 3 Or Greater Than 3.\nBut Your Entered String Length Is",s.len)

else:

    print("No Exception")

    


Comments

Popular posts from this blog

Write a python program to compute cumulative product of a list of numbers (write function cumulative_product).

Write a Python program to compute distance between two points taking input from the user. Formula for Pythagorean theorem for compute distance between two points is: