Knowee
Questions
Features
Study Tools

A person needs to pay Life Insurance Premium, create a class ‘Person’ and get the name, age, Premium Number, Last date for Premium payment, current date and Penalty-per-day information.For ‘age’ create user defined exception class and check if age is a negative number and print “Please enter correct age”.Calculate the total penalty, as days* penalty-per-day. If the total number of days exceeded 5 handle the exception and print “Not Permitted”.If the name entered is not a string, then handle it using exception handling and print “Enter your Correct Name”.Input:Anne18LC7892532022-10-05(last date)2022-10-12(current date)2000(penalty per day)OutputNot Permitted

Question

A person needs to pay Life Insurance Premium, create a class ‘Person’ and get the name, age, Premium Number, Last date for Premium payment, current date and Penalty-per-day information.For ‘age’ create user defined exception class and check if age is a negative number and print “Please enter correct age”.Calculate the total penalty, as days* penalty-per-day. If the total number of days exceeded 5 handle the exception and print “Not Permitted”.If the name entered is not a string, then handle it using exception handling and print “Enter your Correct Name”.Input:Anne18LC7892532022-10-05(last date)2022-10-12(current date)2000(penalty per day)OutputNot Permitted

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The problem is asking to create a class named 'Person' in Python. This class will have attributes like name, age, premium number, last date for premium payment, current date, and penalty-per-day.

Here is the step by step solution:

  1. First, we need to import the datetime module to work with dates.
import datetime
  1. Create a user-defined exception for age.
class AgeException(Exception):
    pass
  1. Create the Person class.
class Person:
    def __init__(self, name, age, premium_no, last_date, current_date, penalty_per_day):
        self.name = name
        self.age = age
        self.premium_no = premium_no
        self.last_date = last_date
        self.current_date = current_date
        self.penalty_per_day = penalty_per_day
  1. In the Person class, create a method to calculate the penalty.
def calculate_penalty(self):
    try:
        if not isinstance(self.name, str):
            raise ValueError("Enter your Correct Name")
        if self.age < 0:
            raise AgeException("Please enter correct age")
        last_date = datetime.datetime.strptime(self.last_date, '%Y-%m-%d')
        current_date = datetime.datetime.strptime(self.current_date, '%Y-%m-%d')
        days = (current_date - last_date).days
        if days > 5:
            raise Exception("Not Permitted")
        total_penalty = days * self.penalty_per_day
        return total_penalty
    except AgeException as ae:
        print(ae)
    except ValueError as ve:
        print(ve)
    except Exception as e:
        print(e)
  1. Now, create an object of the Person class and call the calculate_penalty method.
p = Person('Anne', 18, 'LC789253', '2022-10-05', '2022-10-12', 2000)
p.calculate_penalty()

This will print "Not Permitted" as the number of days exceeded is more than 5.

This problem has been solved

Solution 2

Here is a Python solution for the problem:

import datetime

class AgeException(Exception):
    pass

class Person:
    def __init__(self, name, age, premium_number, last_date, current_date, penalty_per_day):
        try:
            if not isinstance(name, str):
                raise ValueError
            self.name = name
        except ValueError:
            print("Enter your Correct Name")
            return

        try:
            if age < 0:
                raise AgeException
            self.age = age
        except AgeException:
            print("Please enter correct age")
            return

        self.premium_number = premium_number
        self.last_date = datetime.datetime.strptime(last_date, '%Y-%m-%d')
        self.current_date = datetime.datetime.strptime(current_date, '%Y-%m-%d')
        self.penalty_per_day = penalty_per_day

        self.calculate_penalty()

    def calculate_penalty(self):
        days = (self.current_date - self.last_date).days
        try:
            if days > 5:
                raise Exception
            penalty = days * self.penalty_per_day
            print(f'Total penalty is: {penalty}')
        except Exception:
            print("Not Permitted")

person = Person('Anne', 18, 'LC789253', '2022-10-05', '2022-10-12', 2000)

This script creates a Person class with the required attributes. It checks if the age is negative and if the name is a string. It also calculates the penalty based on the number of days and the penalty per day. If the number of days is more than 5, it raises an exception and prints "Not Permitted".

This problem has been solved

Solution 3

The problem is asking to create a class Person in Python that will handle various exceptions and calculate the penalty for late payment of life insurance premium. Here is a step-by-step solution:

import datetime

# User defined exception for age
class AgeException(Exception):
    pass

# User defined exception for exceeded days
class DaysExceededException(Exception):
    pass

class Person:
    def __init__(self, name, age, premium_no, last_date, current_date, penalty_per_day):
        try:
            if not isinstance(name, str):
                raise TypeError
            self.name = name
            if age < 0:
                raise AgeException
            self.age = age
            self.premium_no = premium_no
            self.last_date = datetime.datetime.strptime(last_date, '%Y-%m-%d')
            self.current_date = datetime.datetime.strptime(current_date, '%Y-%m-%d')
            self.penalty_per_day = penalty_per_day
        except TypeError:
            print("Enter your Correct Name")
        except AgeException:
            print("Please enter correct age")

    def calculate_penalty(self):
        try:
            days = (self.current_date - self.last_date).days
            if days > 5:
                raise DaysExceededException
            total_penalty = days * self.penalty_per_day
            return total_penalty
        except DaysExceededException:
            print("Not Permitted")

# Test the class
p = Person('Anne', 18, 'LC789253', '2022-10-05', '2022-10-12', 2000)
p.calculate_penalty()

In this code, we first define two custom exceptions AgeException and DaysExceededException. Then we define the Person class with the required attributes. In the __init__ method, we check if the name is a string and if the age is a positive number. If not, we raise the appropriate exceptions. We also convert the date strings to datetime objects for calculation.

The calculate_penalty method calculates the total penalty by multiplying the number of days late by the penalty per day. If the number of days late is more than 5, we raise the DaysExceededException.

Finally, we create a Person object and call the calculate_penalty method to test the class.

This problem has been solved

Similar Questions

In a College student needs to pay fee, create a class ‘Student’ and get the name, age, Department, Last date for fee payment, current date and Penalty-per-day information. For ‘age’ create user defined exception class and check if age is a negative number and print “Please enter correct age”. Calculate the total penalty as days* penalty-per-day. If the total number of days exceeded 5 handle the exception and print “Not Permitted”.If the name entered is not a string, then handle it using exception handling and print “Enter your Correct Name”. Input:Anne18CSE2022-10-05(last date)2022-10-12(current date)2000(penalty per day)OutputNot Permitted

In an online electric bill system to pay bill, create a class ‘Consumer’ and get the name, consumer number, address, last date for payment, current date and penalty-per-day information. For ‘consumer number’ create user defined exception class and check if it is a negative number and print “Enter correct data”.Calculate the total penalty as (days* penalty-per-day). If the total number of days exceeded 5 handle the exception and print “Not permitted”. (days=current date-last date for payment)If the name entered contains numbers or any special characters (other than alphabets and spaces), then handle it using exception handling and print “Enter correct name”. InputGet the following detailsName (String)Consumer Number (Integer)Address (String)yyyy-mm-dd (last date) (String)yyyy-mm-dd (current date) (String) Penalty in Rs. per day (Integer)outputuser defined string according to the exception occured

In a Library Management System, create a class ‘LibUser’ and get the name, age, address, book name, book type, date of issue, date of return (current date) and penalty amount. For ‘age’ create user defined exception class and check if age is a negative number and print “Please enter correct age”.Calculate the number of days of book in use as (current date - date of issue). If number of days of book in use is greater than 15 days and then handle the exception and print “Fine to be paid + Penalty amount”. Penalty amount = (number of days of book in use – 15) * 10.If the name entered contains numbers or any special characters (other than alphabets and spaces), then handle it using exception handling and print “Enter your Correct Name”.InputName (String)Age (Integer)address (String)book name (String)book type (String)date of issue (format: yyyy-mm-dd) (String)Current date (format: yyyy-mm-dd) (String)OutputUser defined string according to exception

Check whether the person is eligible for a driving license or not. If the age is less than 18, throw an exception and print "InvalidAge" and quit. If the score is less than 40, throw an exception and print "You should get at least 40 marks" and quit. Else print"Passed".Input FormatThe input consists of the age and score separated by a space.Output FormatThe output prints the age, score, and result.Refer to the sample outputs for the formatting specifications.Sample Input12 50Sample OutputInvalid age

write a java program Create a class called “Student” with the following details: Name (should contain only alphabets –No numbers and special characters) Register Number in the format (two numbers three characters four numbers) Age (should be greater than 18 and less than 21) Phone number (10 numbers). Write appropriate Exception handling block (separate block for each type of user defined exception) to handle invalid data entry for all data items. If the valid data is entered construct the email id and password of the student and display Email ID format: first name four-digit year @ vitstudent.ac.in and password is “uppercase of first four characters of name + last four numbers of register number+@” Input Format Enter Name: Enter Reg. Number: Enter Age: Enter Phone Number: Output Format Aditya 19BCE1234 20 1234567890

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.