Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Multiple Exceptions Name and Age

 

 

MULTIPLE EXCEPTIONS NAME AND AGE

 black laptop computer on white textile

The program must accept the name and age of a person as the input. If the length of the name is greater than 2 exception MaximumLengthExceededException 

with the message "name cannot contain more than 20 chara negative, then the program must raise the exception NegativeValueException with the message "age cannot be A program must print the name and age of the person as the output

Please fill in the missing lines of code so that the program runs successfully.

Example Input/Output 1:
Input:
Hector
30

Output:
Hector 30

Example Input/Output 2:
Input:
Catherine
-25

Output:
age cannot be negative or zero

Example Input/Output 3:
Input:
Abcdef 

Ghijklmnopqrst
-10

Output:
name cannot contain more than 20 characters

 

 SOLUTION:

PYTHON CODE :

class NegativeValueException(Exception):
    def __init__(self,S):
        self.S=S
    def__str__(self):
        return self.S
class MaximumLengthExceededException(Exception):
    def __init__(self,S):
        self.S=S
    def __str__(self):

        return self.S 

Post a Comment

Previous Post Next Post