Professional Documents
Culture Documents
Exp 7
Exp 7
7
#Class and objects
class person:
def __init__(self,n,c):
self.name = n
self.city = c
def greet(self):
p1=person("Rutuja","Lanja")
p2=person("Sejal","Malvan")
p3=person("Amey","Ratnagiri")
p4=person("Dikshu","Malvan")
p1.greet()
p2.greet()
p3.greet()
p4.greet()
Output=
Welcome Rutuja from Lanja!
#program
print("\n")
class car:
def __init__(self,m,o,y):
self.make = m
self.model = o
self.year = y
def startengine(self):
def stopengine(self):
c1=car("Audi","A3","2023")
c2=car("Honda","Accord hybrid","2024")
c3=car("Ford","Bronco","2022")
c1.startengine()
c2.startengine()
c3.startengine()
c1.stopengine()
c2.stopengine()
c3.stopengine()
Output=
Audi,A3 of 2023 has started the engine.
print("\n")
class vehicle:
def __init__(self,make,model):
self.make=make
self.model=model
def start(self):
print(f"{self.make},{self.model} is started.")
def stop(self):
print(f"{self.make},{self.model} is stopped.")
class car(vehicle):
def __init__(self,make,model,doors):
super().__init__(make,model)
self.no=doors
def opendoor(self):
def closedoor(self):
c1=car("Toyoto","Camry",5)
c2=car("Kia","C7",6)
c1.start()
c1.opendoor()
c1.closedoor()
c1.stop()
c2.start()
c2.opendoor()
c2.closedoor()
c2.stop()
class bike(vehicle):
def __init__(self,make,model,year):
super().__init__(make,model)
self.year=year
def made(self):
b1=bike("Hero","Xplus",2023)
b2=bike("Royal enfield","Hunter",2022)
b1.start()
b1.made()
b1.stop()
b2.start()
b2.made()
b2.stop()
Output=
Toyoto,Camry is started.
Toyoto,Camry is stopped.
Kia,C7 is started.
Kia,C7-6 doors opened!
Kia,C7 is stopped.
Hero,Xplus is started.
Hero,Xplus is stopped.
#Inheritance
class Admin:
def __init__(self,n,a,m):
self.name = n
self.age = a
self.mobile = m
def Admininfo(self):
print(f"Name of employee is {self.name} and age is {self.age} also mobile used by employee
is {self.mobile}.")
class HR(Admin):
def __init__(self,n,a,m,d,l):
super().__init__(n,a,m)
self.designation = d
self.leaves = l
def HRinfo(self):
print(f"Designation of employee is {self.designation} and leaves by employee are
{self.leaves}.")
class Accounts(HR):
def __init__(self,n,a,m,d,l,s):
super().__init__(n,a,m,d,l)
self.salary = s
def Accountsinfo(self):
a1=Accounts('Dikshita',25,6745,'Manager',17,40000)
a1.Admininfo()
a1.HRinfo()
a1.Accountsinfo()
Output=
Name of employee is Dikshita and age is 25 also mobile used by employee is 6745.