OOPS full form is object oriented programming system.
OOPs full form and OOPs in python programming |
       Â
It is not compalsury to use in python program. It is make our program readable and easy. It make our program pythonic ways.it is also knowns as OOP. There are many class in object orinted programming. They are:
1 Single class
2 Multilevel class
3 Multiple classÂ
class RailwayForm:
formType = "RailwayForm"
haryapplication = RailwayForm()
haryapplication.name = "codebugfree"
print(haryapplication.name)
It is a single class. In single class only one class is define..You can make ticket system libary management system easily write program using opp.
class train():
def__init__(self,name,seats,fare,tickets):
self.name = name
self.seats = seats
self.fare = fare
self.tickets = tickets
def traininfo(self):
print(f"the nam,e of train is {self.name}")
def seatsinfo(self):
print(f"the number of seats available in train{self.seats}")
def fareinfo(self):
print(f"the fare is{self.fare}")
def ticketsinfo(self):
print(f"the price of tickets is rs{self.tickets}")
def bookcount(self):
if self.seats>0:
print(f"now the seats is aviable{self.seats}")
self.seats = self.seats -1
else:
print("seats are not avbialable")
def cacelticket(self):
if self.seats>=0:
print("ticket canacell")
self.seats = self.seats +1
else:
print("ticket is not cancell")
janakpur = train("janakpur express : 444" ,5 ,100,200)
janakpur.seatsinfo()
janakpur.traininfo()
janakpur.ticketsinfo()
janakpur.fareinfo()
janakpur.bookcount()
janakpur.cacelticket()
janakpur.bookcount()
janakpur.bookcount()
janakpur.bookcount()
janakpur.bookcount()
janakpur.bookcount()
janakpur.bookcount()
janakpur.cacelticket()
janakpur.bookcount()
OPPS Basic Project.
This type of program is used in train ticket system.
How you write this program. First we define class and make init construction. Init construction is passed aggrement to object. Object menans (janakpur = train-this is object)(janakpur express:444,5,100,200- it is a aggrement).Def self fuction is run all object and give equally value to all object.Â
class MyCompany(): company = "hanucharya" def__init__(self,name,stage,grade,salary): self.name = name self.stage = stage self.grade = grade self.salary = salary def information(self): print(f"name of worker\t{self.name}\n stage\t{self.stage}\n grade\t {self.grade}\nsalary\t{self.salary}") rahul = MyCompany("rahul","good","A",100000) rahul.information() samir = MyCompany("samir","join","update","review") samir.information()
First Define Mycompany Class. Company class is hanucharya. Make init construction and pass aggrument to object. Def fuction to make with self. It means is automatically work for all object. Define object (rahul = Mycompany) and pass init construction to (rahul good A 1000000) (samir = mycompany) is also object.
Practice OOP Program.
Practice this program and understain this pogram to make master in python program
class programmer():
company = "microsoft"
def __init__(self,name,product):
self.name = name
self.product = product
def programinfo(self):
print(f"name of programmer {self.name}\n name of product {self.product}")
samir = programmer("samir","skype")
alkha = programmer("alkha","github")
samir.programinfo()
class Calculator():
def __init__(self, num):
self.number = num
def square(self):
print(f"the square is {self.number} = {self.number *3}")
def squareroot(self):
print(f"the squareroot is {self.number} = {self.number **3}")
def cube(self):
print(f"the cube is {self.number} = {self.number **3}")
a = Calculator(3)
a.square()
a.squareroot()
a.cube()
1 Comments
Good
ReplyDeleteDon't comment a spam message