OOPS-Python - Jupyter Notebook
OOPS-Python - Jupyter Notebook
OOPS-Python - Jupyter Notebook
In [13]:
class Person:
def __init__(self,name,age,gender):
self.name=name
self.age=age
self.gender=gender
def display(self):
print("Name :",self.name)
print("Age :",self.age)
print("Gender :",self.gender)
def getAge(self):
print(self.age)
def setAge(self,age):
self.age=age
print("The person age has been set to :",self.age)
p=Person("Shiv",12,"Male")
p.display()
p.getAge()
p.setAge(30)
p.getAge()
p.display()
Name : Shiv
Age : 12
Gender : Male
12
The person age has been set to : 30
30
Name : Shiv
Age : 30
Gender : Male
2 ¶
In [35]:
class Person:
def __init__(self,fullname,age):
self.n=fullname
self.a=age
def show(self):
print("Full name :",self.n)
print("Age :",self.a)
class Student(Person):
def __init__(self,fullname,age,Id,major,GPA):
Person.__init__(self,fullname,age)
self.Id=Id
self.major=major
self.GPA=GPA
def getstudentinfo(self):
print(self.Id)
print(self.major)
print(self.GPA)
def setstudentinfo(self,Id,major,GPA):
self.Id=Id
self.major=major
self.GPA=GPA
print("Please find the revised details :")
p=Person("Pooja Rai",25)
print("Person details")
p.show()
s.setstudentinfo("103A","surgery",9)
s.getstudentinfo()
Person details
Full name : Pooja Rai
Age : 25
student details :
102A
Microbiology
8.5
Please find the revised details :
103A
surgery
9
In [2]:
class Rectangle:
def __init__(self,width,height):
self.w=width
self.h=height
def perimeter(self):
print("Perimeter of rectangle is :",2*(self.w+self.h))
def area(self):
print("Area of rectangle is :",(self.w*self.h))
r=Rectangle(width,height)
r.perimeter()
r.area()
4
In [3]:
class Circle:
def __init__(self,radius):
self.r=radius
def perimeter(self):
print("Perimeter of circle is :",(2*3.14*self.r))
def area(self):
print("Area of circle is :",(3.14*self.r**2))
r=Circle(radius)
r.perimeter()
r.area()
In [6]:
class BankAccount:
def __init__(self,balance,interest_rate):
self.b=balance
self.r=interest_rate
def deposit(self,amount):
self.b=self.b+amount
def withdraw(self,amount):
self.b=self.b-amount
def interest1(self):
interest=self.b*self.r
self.b=self.b+interest
print("Current balance :",self.b)
a1=BankAccount(10000,0.07)
a1.deposit(1000)
a1.withdraw(100)
a1.interest1()
In [ ]: