0% found this document useful (0 votes)
3 views

Practical15

The document contains Python code examples demonstrating class inheritance and method overriding, including classes for mathematical shapes (Triangle and Square) and employee/student information management. It showcases how to calculate areas of shapes and read/print employee and student details using user input. The code illustrates object-oriented programming principles such as encapsulation and polymorphism.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical15

The document contains Python code examples demonstrating class inheritance and method overriding, including classes for mathematical shapes (Triangle and Square) and employee/student information management. It showcases how to calculate areas of shapes and read/print employee and student details using user input. The code illustrates object-oriented programming principles such as encapsulation and polymorphism.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical=15

Problem statement:

1. class A: return args[0] + args[1]

def add(self, *args): return super().add(*args)

return sum(args) obj = B()

class B(A): print(obj.add(1, 2))

def add(self, *args): print(obj.add(1, 2, 3))

if len(args) == 2:

2. class Triangle: def __init__(self):

def cal(self, b, h): t1 = Triangle()

A = 0.5 * b * h triangle_area = t1.cal(2, 3)

return A print(f"Area of Triangle: {triangle_area}")

class Square: s1 = Square()

def cal(self, s): square_area = s1.cal(5)

A=s*s print(f"Area of Square: {square_area}")

return A area_obj = Area()

class Area(Triangle, Square):

Exercise:

1. class Employee: self.department = department

def __init__(self, name, department, salary): self.salary = salary

self.name = name def read_employee_info(self):


self.name = input("Enter Employee Name: print(f"Employee Name: {self.name}")
")
print(f"Department: {self.department}")
self.department = input("Enter
Department: ") print(f"Salary: {self.salary}")

self.salary = float(input("Enter Salary: ")) employee = Employee('', '', 0)

def print_employee_info(self): employee.read_employee_info()

employee.print_employee_info()

2. class Person: self.roll_no = roll_no

def __init__(self, name, age): self.grade = grade

self.name = name def read_student_info(self):

self.age = age self.read_person_info()

def read_person_info(self): self.roll_no = input("Enter Roll Number: ")

self.name = input("Enter Name: ") self.grade = input("Enter Grade: ")

self.age = int(input("Enter Age: ")) def print_student_info(self):

def print_person_info(self): self.print_person_info()

print(f"Name: {self.name}") print(f"Roll No: {self.roll_no}")

print(f"Age: {self.age}" print(f"Grade: {self.grade}")

class Student(Person): student = Student('', 0, '', '')

def __init__(self, name, age, roll_no, grade): student.read_student_info()

super().__init__(name, age) student.print_student_info()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy