Professional Documents
Culture Documents
class Person:
self.name = name
self.age = age
def display_info(self):
class Student(Person):
super().__init__(name, age)
self.student_id = student_id
def display_info(self):
super().display_info()
class Teacher(Person):
super().__init__(name, age)
self.employee_id = employee_id
def display_info(self):
super().display_info()
print("Student Information:")
student.display_info()
print("Teacher Information:")
teacher.display_info()
Output:
Student Information:
Name: Sumithra S
Age: 20
Teacher Information:
Name: Raghav K
Age: 35
2.import math
class Shape:
def area(self):
pass
class Rectangle(Shape):
self.length = length
self.width = width
def area(self):
class Circle(Shape):
self.radius = radius
def area(self):
return math.pi *(self.radius ** 2)
rect = Rectangle(15, 7)
circ = Circle(8)
Output:
3.class Vehicle:
def __init__(self,model,make,year):
self.model=model
self.make=make
self.year=year
def display_model(self):
print(f"Model: {self.model}")
class Car(Vehicle):
def __init__(self,model,make,year,milege):
super().__init__(model,make,year)
self.milege=milege
def display_info(self):
print(f"Model: {self.model}")
print(f"make: {self.make}")
print(f"make: {self.year}")
print(f"make: {self.milege}")
class Motorcycle(Vehicle):
def __init__(self,make,model,year,color):
super().__init__(make,model,year)
self.color=color
def display_info(self):
print(f"make : {self.make}")
print(f"model : {self.model}")
print(f"year : {self.year}")
print(f"Color: {self.color}")
car1=Car("Baleno","Maruty",2020,15)
motorcycle1=Motorcycle("Pulsor","Honda",2001,"Black")
car1.display_info()
motorcycle1.display_info()
Output:
Model: Baleno
make: Maruty
make: 2020
make: 15
make : Honda
model : Pulsor
year : 2001
Color: Black
4. class Animal:
self.species = species
pass
class Mammal(Animal):
super().__init__(name, species)
self.fur_color = fur_color
def give_birth(self):
class Bird(Animal):
self.feather_color = feather_color
def lay_eggs(self):
lion.give_birth()
parrot.lay_eggs()
Output:
5. class Book:
self.title = title
self.author = author
self.genre = genre
def display_info(self):
self.subgenre = subgenre
def display_info(self):
fiction_info = super().display_info()
self.subject = subject
def display_info(self):
non_fiction_info = super().display_info()
return f"{non_fiction_info}, Subject: {self.subject}"
class ScienceFictionBook(FictionBook):
self.theme = theme
def display_info(self):
sci_fi_info = super().display_info()
print(fiction_book.display_info())
print(non_fiction_book.display_info())
print(sci_fi_book.display_info())
Output: