You are on page 1of 6

Experiment NO.

7
#Class and objects

class person:

def __init__(self,n,c):

self.name = n

self.city = c

def greet(self):

print(f"Welcome {self.name} from {self.city}!")

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!

Welcome Sejal from Malvan!

Welcome Amey from Ratnagiri!

Welcome Dikshu from Malvan!

#program

print("\n")

class car:
def __init__(self,m,o,y):

self.make = m

self.model = o

self.year = y

def startengine(self):

print(f"{self.make},{self.model} of {self.year} has started the engine.")

def stopengine(self):

print(f"{self.make},{self.model} of {self.year} has stopped the engine.")

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.

Honda,Accord hybrid of 2024 has started the engine.

Ford,Bronco of 2022 has started the engine.

Audi,A3 of 2023 has stopped the engine.

Honda,Accord hybrid of 2024 has stopped the engine.

Ford,Bronco of 2022 has stopped the engine.


#Inheritance

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):

print(f"{self.make},{self.model}-{self.no} doors opened!")

def closedoor(self):

print(f"{self.make},{self.model}-{self.no} doors closed!")

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):

print(f"{self.make},{self.model} is made in {self.year}.")

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-5 doors opened!

Toyoto,Camry-5 doors closed!

Toyoto,Camry is stopped.

Kia,C7 is started.
Kia,C7-6 doors opened!

Kia,C7-6 doors closed!

Kia,C7 is stopped.

Hero,Xplus is started.

Hero,Xplus is made in 2023.

Hero,Xplus is stopped.

Royal enfield,Hunter is started.

Royal enfield,Hunter is made in 2022.

Royal enfield,Hunter 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):

print(f"Salary of employee is {self.salary}.")

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.

Designation of employee is Manager and leaves by employee are 17.

Salary of employee is 40000.

You might also like