Slip 18 - B) Write a python script to define the class person having members name, address. Create a subclass called Employee with members staffed salary. Create 'n' objects of the Employee class and display all the details of the employee.
Solution :
1 Comments
# Write a python script to define the class person having members name, address. Create a subclass called Employee with members staffed salary. Create 'n' objects of the Employee class and display all the details of the employee.
ReplyDeleteclass Person:
def __init__(self, name, address):
self.name = name
self.address = address
def display(self):
print(f"Name: {self.name}")
print(f"Address: {self.address}")
class Employee(Person):
def __init__(self, name, address, salary):
super().__init__(name, address)
self.salary = salary
def display(self):
super().display()
print(f"Salary: {self.salary}")
n = int(input("Enter number of employees: "))
employees = []
for i in range(n):
print(f"\nEnter details for employee {i + 1}:")
name = input("Enter name: ")
address = input("Enter address: ")
salary = input("Enter salary: ")
employees.append(Employee(name, address, salary))
i = 1
for employee in employees:
print(f"\nEmployee {i} details:")
employee.display()
i += 1