Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

OOPS in Python:-


Object-Oriented Programming Structure, it is used to create a real-world based application using class and object.

OOP'S programming is based on Object because we will define the characteristics and behavior of Objects using class.


OOP provides better security, reusability, modularity, extendibility, usability, and accessibility features in real-world applications.


OOP provides individual memory allocation to individual objects for individual users.


Rule's of OOP'S:-

1 Class and Object:-

Class:-

It is user define datatype which is used to define the characteristics of an object using data member (variable) and member function(method).class is a blueprint of an object, we can define multiple objects definition underclass but all object should be related with each other.

class Classname:
    def methodname(self):
        statements
        statements
    ...
    ...

ref = Classname()    #object
ref.methodname()    # calling of method

self is a keyword that is used to contain the address of the current object.


Example of a Student object that represents the characteristics of Student using rno and name that has been defined as to accept() and display().




class Student:
    def accept(self):
        self.rno= input("Enter rno")
        self.sname= input("Enter name")
    def display(self):
        print("Rno is ",self.rno, " name is ",self.sname)


obj = Student()
obj.accept()
obj.display()

obj1 = Student()
obj1.accept()
obj1.display()


        


Object:-

It is a real-world entity that has identity, state, and behavior.  Identity provides the address of the object which will be unique.  Memory allocation of objects is used to specify the state, and the calling of the method will be defined as the behavior of the object.


"for example apple, orange these are the objects which will be defined by Fruit class".


if we want to create Object by python script:-

ref =  Classname()

ref = Student()


Example of Class and Object?

class Employee:
    def accept(self,empid,empname,job,salary):
        self.empid=empid
        self.empname=empname
        self.job=job
        self.salary=salary
    def display(self):
        print("ID is "+str(self.empid))
        print("name is "+str(self.empname))
        print("job is "+str(self.job))
        print("salary is "+str(self.salary))
obj = Employee()
obj.accept(1001,"XYZ","CLEARK",15000)
obj.display()
obj1 = Employee()
obj1.accept(1002,"MNO","MANAGER",25000)
obj1.display()
       
................................................................................................................................

Program to accept and display student record:-

class Student:
    def accept(self,rno,sname,branch,fees):
        self.rno=rno
        self.sname=sname
        self.branch=branch
        self.fees=fees

    def display(self):
        print("rno is "+str(self.rno) + " name is "+self.sname + " branch is " + self.branch +" fees is "+str(self.fees));

obj = Student()
obj.accept(1001,"xyz","CS",45000)
obj.display()

obj1 = Student()
obj1.accept(1002,"mno","IT",70000)
obj1.display()




Assignment:-

1)  WAP to manage five student records using rno, marks, and age and display max-age and max marks of students?

2)  WAP to calculate the prime number, factorial, and Fibonacci series program using oops with three lasses and three  methods (accept, logic, display)

Solution of Factorial Program:-

class Fact:
    def accept(self,num):
        self.num = num
    def calcFact(self):
        f=1
        self.result=""
        for i in range(self.num,1,-1):
            f=f*i
        else:
            self.result = "Result of factorial is "+str(f)

    def display(self):
        print(self.result)


obj = Fact()
obj.accept(int(input("Enter number to calculate factorial")))
obj.calcFact()
obj.display()
            
Solution of Fibonacci Series based Program:-

class Fibonacci:
    
    def accept(self,num):
        self.num = num
        
    def cFab(self):
        a=-1
        b=1
        self.result=""
        for i in range(1,self.num+1):
            c=a+b
            self.result += str(c) + "\n"
            a=b
            b=c
        

    def display(self):
        print(self.result)


obj = Fibonacci()
obj.accept(int(input("Enter number of terms")))
obj.cFab()
obj.display()

Component of class:-

1 Data member or variable:-
  
It is used to define attributes of the object for example Employee object contains Empid, Empname, job, etc as an attribute of this, it will be declared as a variable.

We can define a data member using two different types:-

1.1)  class type or static:-  it will be declared underclass or static method, this type of variable use class memory to store data.
static variable memory will be fixed means it has a single memory on the complete program.
The static variable will call using Classname no need to create an object.


   class Classname:
       a=10  #class type


Example of Static Data Member in Python:-

class A:
    a=100   #class type or static
    b=200


c = A.a+A.b
print(c)


#WAP to calculate Simple Interest using static data member only

class SI:
    p,r,t = 140000,2,2  #class type

res = (SI.p* SI.r* SI.t)/100
print(res)


note:-  It will be used to declare a shared variable in the program.

class StaticVar:
    schoolname = "IPS Academy"

print(StaticVar.schoolname)    


Complete example of Static:-
class StaticVar:
    schoolname = "IPS Academy"   #class type
    def fun():       #class type method
        a=10  #local class type
        print(a)
        print(StaticVar.schoolname)


print(StaticVar.schoolname)
StaticVar.fun()


1.2) instance type or dynamic:- It will be declared by self keyword under dynamic method

  class Classname:
        def methodname(self):
           b=20    #local instance 
           self.a=100   #global instance type  variable


Example of Instance variable:-

class A:
    def fun(self,a,b):
     self.a=a   #instance type or dynamic
     self.b=b
    def display(self):
        print(self.a, self.b)


obj = A()
obj.fun(10,20)
obj.display()

obj1 = A()
obj1.fun(30,40)
obj1.b=500
obj1.display()

#WAP to calculate Simple Interest using dynamic data member only

class SI:
    def fun(self,p,r,t):
     self.p,self.r,self.t = p,r,t
     res = (self.p* self.r* self.t)/100
     print(res)

obj = SI()
obj.fun(450000,2,2)


Program Solution:-

class Datamemberexample:
    a=100  #class type
    def fun(self):
        self.b=200    #reference type
        print(self.b)


obj =  Datamemberexample()
obj.fun()
print(Datamemberexample.a)  #class name
      

2 Member function or function:-

It is used to define data member of the class to implement data encapsulation

Type of member function

2.1 )  class type or static:-

It is used to define class-type variables in the program.it does not use self keyword to declare method parameters.

 class Classname:
       def Methodname():
             statements
             statements


Classname.Methodname()

It has only a one-time memory allocation in the program because it will use the Class memory of the program.

Example of Static:-
class StaticFunction:
       def fun():
           a=int(input("enter first number"))
           b=int(input("enter second number"))
           c=a+b
           print(c)

StaticFunction.fun()
StaticFunction.fun()


2.2) Instance type or dynamic:-

this type of member function will be declared using the self keyword and called by object .it will be allocated individual memory for the different objects because it has a unique address for Object.
 

   class DynamicFunction:
       def fun(self):
           a=int(input("enter first number"))
           b=int(input("enter second number"))
           c=a+b
           print(c)

obj=DynamicFunction()
obj.fun()
obj1=DynamicFunction()
obj1.fun()



Standard Program Example using OOPS:-

class SI:
    def accept(self,p,r,t):
        self.p=p
        self.r=r
        self.t=t

    def logic(self):
        self.si = (self.p*self.r*self.t)/100

    def display(self):
        print("Result is ",self.si)

obj = SI()
p = float(input("Enter amount"))
r = float(input("Enter rate"))
t = float(input("Enter time"))
obj.accept(p,r,t)
obj.logic()
obj.display()


        


 3 Constructor or Init Method:-

   It is a special component of the class that will be called when we create an object. A constructor is used to initializing the dynamic data member of the class.

In Python constructor will be declared by __init__() method,


class Consdemo:
      def __init__(self):
          statements




Example of Constructor:-

class SI:
    
    def __init__(self,p,r,t):
        self.p=p
        self.r=r
        self.t=t

    def logic(self):
        self.si = (self.p*self.r*self.t)/100

    def display(self):
        print("Result is ",self.si)
        
p = float(input("Enter amount"))
r = float(input("Enter rate"))
t = float(input("Enter time"))
obj = SI(p,r,t)
obj.logic()
obj.display()


        

Type of Constructor?

1 Single parameter:-

  we can pass only self as a parameter to a single parameter constructor, it is also called default constructor, it will be created automatically at the time of execution.

class A:
    def __init__(self):
        statements

2  Multiple Parameter:-

  We can pass multiple values as an argument to multiple parameter constructors.

class A:
   def __init__(self,a,b):
       self.a=10
       self.b=20



Note:  we should create only one type of constructor in the program because only one constructor will be called.

The constructor is only for dynamic data member initialization not to write the functionality.



4 Destructor or Delete Method:-

This method will be called when we destroy or delete the object, It is used to remove dynamic memory space in the program that is created by the construtor.
this block by default created by class, if we want to implement any functionality then we can manually re-create the destructor.


Syntax of destructor:-

class Abc:

  def __del__(self):
      Sattement1
      Statement2



How to call destructor manually

obj = Abc()
del obj // means destructor will be called

Complete Program Explanation of Constructor and Destructor:-

class Addition:
    def __init__(self):
        self.a=100
        self.b=200
    def __init__(self,a,b):
        self.a=a
        self.b=b
    def add(self):
        print("result is "+str(self.a+self.b))
    def __del__(self):
        print("Destructor will be called")

obj = Addition(10,20)
obj.add()

del obj


Data Abstraction and Data Encapsulation:-

  Data abstraction:-

  To show essential details and hide non-essential details in the program is managed by data abstraction.
it is used to provide data hiding from end-users in an application.It is used to implement security and accessibility features in the program.

  How to implement Data abstraction practically:-

  we will use access specifier, python support access specifier using the symbol


  if we use  __   private   (accessed in the same class, means it can not access outside of the class)
  if we use  _    protected (accessed from base class to derived class )
  if we use        without symbol then public (accessed in all classes by default python member function is public)

class Classname:
    def __fun(self):
        print("Private")
    def _fun2(self):
       print("Protected")
    def fun3(self):
      print("public")



Example of Data abstraction in python:-

class A:
  def __fun(self):
      print("Private")
  def _fun2(self):
      print("Protected")
  def fun3(self):
      self.__fun()
      print("public")

obj = A()
obj.fun3()


Example of Data abstraction using Bank Class With Credit, Debit, and Login Functions.


class Bank:
    balance=500000
    def __debit(self,amount):  #private method
        self.balance-=amount
        print("Current balance is ",self.balance)
        print("Debit Amount is ",amount)

    def __credit(self,amount):  #private method
        self.balance+=amount
        print("Current balance is ",self.balance)
        print("Credit Amount is ",amount)
        
    def login(self,pin):  #public method
        if pin==12345:
            self.__credit(int(input("enter amount")))
            self.__debit(int(input("enter amount")))

obj = Bank()
obj.login(12345)


                        
        
Data Encapsulation:-

It is used to bind all the details using a single unit. if we declare data members under the member function then it is called data encapsulation. we will use a data binding principle to implement encapsulation functionality.
 In the python script, we can not access any instance type data member directly .instance type variable will be defined by self keyword under member function.

accessing all non-accessible methods under the accessible method is also called data encapsulation.

class A:

  a=1000  #class type
  def fun(self):
   a=10   #local instance type
   print(A.a)  #call class type
   print(a)    #call local instance type
   self.a=100
  def fun1(self):
    print(self.a)  #call self type
    print(A.a)     #call class type


obj = A()
obj.fun()
obj.fun1()





3 Polymorphism:-

Poly means many and morph-ism means forms, using this we will create the same name method or operator which will be implemented into multiple forms.

function overloading, operator overloading, and function overriding is the practical example of Polymorphism.

Function Overloading is not managed by python script because we can define multiple functions but call only one function at a time.


Operator overloading:-  using this we can reload or redefine the operator definition.  A single operator can be used in multiple forms using an operator overloading concept.

python use a predefined method to implement operator definition:-

1 function  __add__(self):
       statements

2 function  __sub__(self):
       statements

3 function  __mul__(self):
      statements

4  function __truediv__(self):
       statements

5   function __floordiv__(self):
         statements


Operator overloading example in Python using + Operator:-

class Ope:
    def __init__(self,num):
        self.num=num
    def __add__(self,other):
        return Ope(self.num*other.num)
    def __str__(self):  #TO RETURN VALUE OF CURRENT OBJECT WHEN WE PRINT(OBJ) THEN IT CALL
        return "result is "+str(self.num)


obj = Ope(100)
obj1 = Ope(200)
obj3 = obj + obj1   #__add__(obj,obj1)
print(obj3)



Function Overriding:-

We will create the same name and same parameters function from base class to derived class, base class method automatically override into child class method.
It is used to replace the old functionality of the method with new functionality.

to implement function overriding, inheritance is mandatory.


Syntax of Function Overriding in Python:-


class ParentClassName:
    def MethodName(self):
          Statement


class ChildClass(ParametClassName):
        def MethodName(self):
            New Statement
        


obj = ChildClass()
obj.MethodName(); 
 

Now I am providing an example of method overriding to create Exam class and Examnew class to replace some functionality.  I have replaced exam-pattern and exam mode() only.


class Exam:
    def ExamDuration(self):
        print("3 Hours")

    def ExamPattern(self):
        print("Number System")

    def ExamMode(self):
        print("OFFline")

    def Syllabus(self):
        print("Outdated")


class ExamNew(Exam):
    def ExamPattern(self):
        print("Grade System")

    def ExamMode(self):
        print("ONLINE")


obj = ExamNew()
obj.ExamDuration()
obj.ExamPattern()
obj.ExamMode()
obj.Syllabus()


 


Assignment:-

Overload + operator to convert dollar to rs and rs to dollar in a single program?

Overload / and // operator?

Overload * the operator, multiply the result with GST?

Create FunctionOverridng program to override Corona various 1.0 and 2.0.




4 Inheritance:-  


It is used to provide re-usability means we can adapt the features of base class to the derived class.

Type of Inheritance:-

4.1) Single  Inheritance:-

From Base Class to Derived Class

class A:
    methods

class B(A):
    methods

4.2) Multilevel  Inheritance:-

From base class to derived class and derived class to sub derived class.
class A:
    methods
class B(A):
    methods
class C(B):
   methods


class A:
    def fun(self):
        print("A")



class B(A):
    def fun1(self):
        super().fun()
        print("B")


class C(B):
    def fun2(self):
        super().fun1()
        print("C")


obj = C()
#obj.fun()
#obj.fun()
#obj.fun1()

obj.fun2()


4.3) Hierarchical  Inheritance:-

 One base class to different child class

class A:
   methods

class B(A):
   methods

class C(A):
    methods

4.4)  Multiple Inheritance:-

 Two base classes in one child class

class A:
     methods


class B:
    methods


class C(A, B):
    methods


   


Example of Single Inheritance:-


ADMIN ------>  EMPLOYEE

class Admin:
    def accept(self,id,name):
        self.id=id
        self.name=name

    def display(self):
        print("ID is "+str(self.id)+" name is "+str(self.name))

class Employee(Admin):
    def accept1(self,sal):
        self.sal=sal
    def display1(self):
        print("Salary is "+str(self.sal))

print("Employee Information")
obj = Employee()
obj.accept(1001,"emp")
obj.accept1(12000)
obj.display()
obj.display1()

print("Admin Info")
obj1 = Admin()
obj1.accept(1000,"admin")

obj1.display()

Example of Multilevel Inheritance:-

ADMIN -----> EMPLOYEE------> OTHERSTAFF

class Admin:
    def accept(self,id,name):
        self.id=id
        self.name=name

    def display(self):
        print("ID is "+str(self.id)+" name is "+str(self.name))

class Employee(Admin):
    def accept1(self,sal):
        self.sal=sal
    def display1(self):
        print("Salary is "+str(self.sal))


class Otherstaff(Employee):
    def accept2(self,bonus):
        self.bonus=bonus
    def display2(self):
        print("Bonus is "+str(self.bonus))

print("Employee Information")
obj = Employee()
obj.accept(1001,"emp")
obj.accept1(12000)
obj.display()
obj.display1()

print("Admin Info")
obj1 = Admin()
obj1.accept(1000,"admin")
obj1.display()

print("Other Staff Info")
obj2 = Otherstaff()
obj2.accept(1002,"otherstaff")
obj2.accept1(12000)
obj2.accept2(200)
obj2.display()
obj2.display1()

obj2.display2()


Example of Hierarchical Inheritance:-

                            ADMIN


EMPLOYEE                                                  OTHERSTAFF

class Admin:
    def accept(self,id,name):
        self.id=id
        self.name=name

    def display(self):
        print("ID is "+str(self.id)+" name is "+str(self.name))



class Employee(Admin):
    def accept1(self,sal):
        self.sal=sal
    def display1(self):
        print("Salary is "+str(self.sal))



class Otherstaff(Admin):
    def accept2(self,bonus):
        self.bonus=bonus
    def display2(self):
        print("Bonus is "+str(self.bonus))

print("Employee Information")
obj = Employee()
obj.accept(1001,"emp")
obj.accept1(12000)
obj.display()
obj.display1()

print("Admin Info")
obj1 = Admin()
obj1.accept(1000,"admin")
obj1.display()

print("Other Staff Info")
obj2 = Otherstaff()
obj2.accept(1002,"otherstaff")
#obj2.accept1(12000)
obj2.accept2(200)
obj2.display()
#obj2.display1()

obj2.display2()
..................................................................................

Example of Multiple Inheritance:-

ADMIN                         EMPLOYEE


                     OTHERSTAFF

class Admin:
    def fun(self):
        print("Admin")
    def accept(self,id,name):
        self.id=id
        self.name=name

    def display(self):
        print("ID is "+str(self.id)+" name is "+str(self.name))

class Employee:
    def fun(self):
        print("Employee")
    def accept1(self,sal):
        self.sal=sal
    def display1(self):
        print("Salary is "+str(self.sal))
class Otherstaff(Admin,Employee):
    def accept2(self,bonus):
        self.bonus=bonus
    def display2(self):
        print("Bonus is "+str(self.bonus))

print("Employee Information")
obj = Employee()
#obj.accept(1001,"emp")
obj.accept1(12000)
#obj.display()
obj.display1()

print("Admin Info")
obj1 = Admin()
obj1.accept(1000,"admin")
obj1.display()

print("Other Staff Info")
obj2 = Otherstaff()
obj2.fun()
obj2.accept(1002,"otherstaff")
obj2.accept1(12000)
obj2.accept2(200)
obj2.display()
obj2.display1()

obj2.display2()



.....................................................................................................................................................

Inheritance Example for Area of the circle, triangle, and rectangle:-

class Circle:
    def accept(self,param1):
        self.param1=param1
    def areaofcirlce(self):
        self.area = 3.14*self.param1*self.param1
    def display(self):
        print("Area  is "+str(self.area))

class Triangle(Circle):
    def accept1(self,param2):
        self.param2=param2
    def areaoftriangle(self):
        self.area = (self.param1*self.param2)/2

class Rect(Triangle):
    def areaofrectangle(self):
        self.area = (self.param1*self.param2)

print("Area of the circle")
obj = Circle()
obj.accept(12)
obj.areaofcirlce()
obj.display()
print("Area of Triangle")
obj1 =Triangle()
obj1.accept(12)
obj1.accept1(2)
obj1.areaoftriangle()
obj1.display()
print("Area of Rectangle")
obj2 =Rect()
obj2.accept(12)
obj2.accept1(2)
obj2.areaofrectangle()
obj2.display()
   

Function Overriding:-

we can create the same name method from base class to derived class only functionality will be different.

no need to use any keyword for function overriding, it will be implemented automatically.

class A:
    def fun(self):
        print("A")

class B(A):
    def fun(self):
        print("B")

        
obj = B()
obj.fun()
    


Example of Inheritance:-

class Course:
    def accept(self,courseid,coursename):
        self.courseid=courseid
        self.coursename=coursename

    def display(self):
        print("courseid is"+str(self.courseid) + "coursename is "+self.coursename)


class Student(Course):
    def accept1(self,name):
        self.name=name
    def display1(self):
        print("name is "+self.name)



obj = Course()
obj.accept(1001,"Java")
obj.display()

obj1 = Student()
obj1.accept(1002,".NET")
obj1.accept1("Manish")
obj1.display()
obj1.display1()




Assignment:-

1)  Manage Patient, Doctor, and Appointment using all possible Inheritance?

2)  Manage Coach, Team, and Player using all possible Inheritance?


3)  Manage Branch, Location, and Institute using all possible Inheritance




How to call class under Module?

we can call module using two ways

1)  import filename

2)  from filename import Classname


Practice Example:-

1)  Create First StrExample.py

class A:
     def __init__(self):
         self.a=10
     def __str__(self):
         return str(self.a)



2)  Call this module into another file

#import StrExample
from StrExample import A

obj = A()
print(obj)










        







86 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. doubt-not able to understand this question
    class Dog:
    def __init__(self, name, age):
    self.name = name
    self.age = age
    The correct way to instantiate the above Dog class is:

    ReplyDelete
  2. class Dog:
    ... def walk(self):
    ... return "*walking*"
    ...
    ... def speak(self):
    ... return "Woof!"
    ...
    >>> class JackRussellTerrier(Dog):
    ... def speak(self):
    ... return "Arff!"
    ...
    >>> bobo = JackRussellTerrier()
    >>> bobo.speak()
    output of this program is Arff could not understand

    ReplyDelete
  3. class Dog:
    def __init__(self, name, age):
    self.name = name
    self.age = age

    class JackRussellTerrier(Dog):
    pass

    class Dachshund(Dog):
    pass

    class Bulldog(Dog):
    pass

    miles = JackRussellTerrier("Miles", 4)
    buddy = Dachshund("Buddy", 9)
    jack = Bulldog("Jack", 3)
    jim = Bulldog("Jim", 5)
    output-isinstance(miles,bulldog)

    ReplyDelete
  4. class Person:
    def __init__(self, id):
    self.id = id

    sam = Person(100)

    sam.__dict__['age'] = 49

    print (sam.age + len(sam.__dict__))
    output is 51 how please explain it

    ReplyDelete
  5. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    #single inheritance
    class Doctor:
    def Doctorinfo(self,specality,location):
    self.specality=specality
    self.location=location
    def display(self):
    print("specality"+str(self.specality),"location"+str(self.location))
    class Patient(Doctor):
    def Patientinfo(self,id,name,age):
    self.id=id
    self.name=name
    self.age=age
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.age))
    class Appointement(Patient):
    def appoint(self,time):
    self.time=time
    def display2(self):
    print("time is "+str(self.time))
    print("doctor info")
    obj=Doctor()
    obj.Doctorinfo("surgoen","indore")
    obj.display()
    print("patient info")
    obj1=Patient()
    obj1.Patientinfo(101,"abc",40)
    obj1.Doctorinfo("neurosurgeon","bhopal")
    obj1.display()
    obj1.display1()
    print("appointement info")
    obj2=Appointement()
    obj2.Doctorinfo("eyespecalist","india")
    obj2.Patientinfo(102,"xyz",40)
    obj2.appoint("6pm")
    obj2.display()
    obj2.display1()
    obj2.display2()

    ReplyDelete
  6. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    # Hierarchical inheritance
    class Doctor:
    def Doctorinfo(self,specality,location):
    self.specality=specality
    self.location=location
    def display(self):
    print("specality"+str(self.specality),"location"+str(self.location))
    class Patient(Doctor):
    def Patientinfo(self,id,name,age):
    self.id=id
    self.name=name
    self.age=age
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.age))
    class Appointement(Doctor):
    def appoint(self,time):
    self.time=time
    def display2(self):
    print("time is "+str(self.time))
    print("doctor info")
    obj=Doctor()
    obj.Doctorinfo("surgoen","indore")
    obj.display()
    print("patient info")
    obj1=Patient()
    obj1.Patientinfo(101,"abc",40)
    obj1.Doctorinfo("neurosurgeon","bhopal")
    obj1.display()
    obj1.display1()
    print("appointement info")
    obj2=Appointement()
    obj2.Doctorinfo("eyespecalist","india")
    obj2.appoint("6pm")
    obj2.display()
    obj2.display2()






















































    ReplyDelete
  7. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    # multiple inheritance
    class Doctor:
    def Doctorinfo(self,specality,location):
    self.specality=specality
    self.location=location
    def display(self):
    print("specality"+str(self.specality),"location"+str(self.location))
    class Patient():
    def Patientinfo(self,id,name,age):
    self.id=id
    self.name=name
    self.age=age
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.age))
    class Appointement(Doctor,Patient):
    def appoint(self,time):
    self.time=time
    def display2(self):
    print("time is "+str(self.time))
    print("doctor info")
    obj=Doctor()
    obj.Doctorinfo("surgoen","indore")
    obj.display()
    print("patient info")
    obj1=Patient()
    obj1.Patientinfo(101,"abc",40)
    obj1.display1()
    print("appointement info")
    obj2=Appointement()
    obj2.Doctorinfo("eyespecalist","india")
    obj2.Patientinfo(101,"xyz",50)
    obj2.appoint("6pm")
    obj2.display()
    obj2.display1()
    obj2.display2()






















































    ReplyDelete
  8. #Manage Coach, Team, and Player using all possible Inheritance?
    #multilevel inheritance
    class Team:
    def Teaminfo(self,country,group):
    self.country=country
    self.group=group
    def display(self):
    print("country"+str(self.country),"group"+str(self.group))
    class Coach(Team):
    def Coachinfo(self,id,name,age):
    self.id=id
    self.name=name
    self.age=age
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.age))
    class Player(Coach):
    def Playerinfo(self,age):
    self.age=age
    def display2(self):
    print("age of player "+str(self.age))
    print("Team info")
    obj=Team()
    obj.Teaminfo("india","A")
    obj.display()
    print("coach info")
    obj1=Coach()
    obj1.Coachinfo(101,"abc",40)
    obj1.Teaminfo("austraila","B")
    obj1.display()
    obj1.display1()
    print("player info")
    obj2=Player()
    obj2.Teaminfo("eyespecalist","india")
    obj2.Coachinfo(102,"xyz",20)
    obj2.Playerinfo(20)
    obj2.display()
    obj2.display1()
    obj2.display2()

    ReplyDelete
  9. #Manage Coach, Team, and Player using all possible Inheritance?
    #heiarchial inheritance
    class Team:
    def Teaminfo(self,country,group):
    self.country=country
    self.group=group
    def display(self):
    print("country"+str(self.country),"group"+str(self.group))
    class Coach(Team):
    def Coachinfo(self,id,name,age):
    self.id=id
    self.name=name
    self.age=age
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.age))
    class Player(Team):
    def Playerinfo(self,age):
    self.age=age
    def display2(self):
    print("age of player "+str(self.age))
    print("Team info")
    obj=Team()
    obj.Teaminfo("india","A")
    obj.display()
    print("coach info")
    obj1=Coach()
    obj1.Coachinfo(101,"abc",40)
    obj1.Teaminfo("austraila","B")
    obj1.display()
    obj1.display1()
    print("player info")
    obj2=Player()
    obj2.Teaminfo("eyespecalist","india")
    obj2.Playerinfo(30)
    obj2.display()
    obj2.display2()


    ReplyDelete
  10. #Manage Coach, Team, and Player using all possible Inheritance?
    #multiple inheritance
    class Team:
    def Teaminfo(self,country,group):
    self.country=country
    self.group=group
    def display(self):
    print("country"+str(self.country),"group"+str(self.group))
    class Coach():
    def Coachinfo(self,id,name,age):
    self.id=id
    self.name=name
    self.age=age
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.age))
    class Player(Team,Coach):
    def Playerinfo(self,age):
    self.age=age
    def display2(self):
    print("age of player "+str(self.age))
    print("Team info")
    obj=Team()
    obj.Teaminfo("india","A")
    obj.display()
    print("coach info")
    obj1=Coach()
    obj1.Coachinfo(101,"abc",40)
    obj1.display1()
    print("player info")
    obj2=Player()
    obj2.Teaminfo("india","C")
    obj2.Coachinfo(103,"pakistan",20)
    obj2.Playerinfo(30)
    obj2.display()
    obj2.display1()
    obj2.display2()


    ReplyDelete
  11. #Manage Branch, Location, and Institute using all possible Inheritanc
    #multilevel inheritance
    class Insitute:
    def insituteinfo(self,name,location):
    self.name=name
    self.location=location
    def display(self):
    print("specality"+str(self.name),"location"+str(self.location))
    class Branch(Insitute):
    def branchinfo(self,id,name,pincode):
    self.id=id
    self.name=name
    self.pincode=pincode
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.pincode))
    class location(Branch):
    def locatinfo(self,address):
    self.address=address
    def display2(self):
    print("adress is "+str(self.address))
    print("insitute info")
    obj=Insitute()
    obj.insituteinfo("ips","indore")
    obj.display()
    print("branch info")
    obj1=Branch()
    obj1.branchinfo(101,"abc",453)
    obj1.insituteinfo("ibp","bhopal")
    obj1.display()
    obj1.display1()
    print("location info")
    obj2=location()
    obj2.insituteinfo("lnct","india")
    obj2.branchinfo(102,"xyz",407)
    obj2.locatinfo("anfsdjf")
    obj2.display()
    obj2.display1()
    obj2.display2()




    ReplyDelete
  12. #Manage Branch, Location, and Institute using all possible Inheritanc
    #Hierarchica inheritance
    class Insitute:
    def insituteinfo(self,name,location):
    self.name=name
    self.location=location
    def display(self):
    print("specality"+str(self.name),"location"+str(self.location))
    class Branch(Insitute):
    def branchinfo(self,id,name,pincode):
    self.id=id
    self.name=name
    self.pincode=pincode
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.pincode))
    class location(Insitute):
    def locatinfo(self,address):
    self.address=address
    def display2(self):
    print("adress is "+str(self.address))
    print("insitute info")
    obj=Insitute()
    obj.insituteinfo("ips","indore")
    obj.display()
    print("branch info")
    obj1=Branch()
    obj1.branchinfo(101,"abc",453)
    obj1.insituteinfo("ibp","bhopal")
    obj1.display()
    obj1.display1()
    print("location info")
    obj2=location()
    obj2.insituteinfo("lnct","india")
    obj2.locatinfo("anfsdjf")
    obj2.display()
    obj2.display2()




    ReplyDelete
  13. #Manage Branch, Location, and Institute using all possible Inheritanc
    #multiple inheritance
    class Insitute:
    def insituteinfo(self,name,location):
    self.name=name
    self.location=location
    def display(self):
    print("specality"+str(self.name),"location"+str(self.location))
    class Branch:
    def branchinfo(self,id,name,pincode):
    self.id=id
    self.name=name
    self.pincode=pincode
    def display1(self):
    print("id is"+str(self.id),"name"+str(self.name),"age"+str(self.pincode))
    class location(Insitute,Branch):
    def locatinfo(self,address):
    self.address=address
    def display2(self):
    print("adress is "+str(self.address))
    print("insitute info")
    obj=Insitute()
    obj.insituteinfo("ips","indore")
    obj.display()
    print("branch info")
    obj1=Branch()
    obj1.branchinfo(101,"abc",453)
    obj1.display1()
    print("location info")
    obj2=location()
    obj2.insituteinfo("lnct","india")
    obj2.branchinfo(101,"sad",20)
    obj2.locatinfo("anfsdjf")
    obj2.display()
    obj2.display2()




    ReplyDelete
  14. Program of Multilevel inheritance for Doctor,Patient,Appointment-->>

    class Doctor:
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("Id is"+str(self.id)+"Name is"+str(self.name))

    class Patient(Doctor):
    def accept1(self,name):
    self.name=name
    def display1(self):
    print("Name is"+str(self.name))

    class Appointment(Patient):
    def accept2(self,time):
    self.time=time
    def display2(self):
    print("Time is"+str(self.time))

    print("Doctor information")
    obj=Doctor()
    obj.accept(420,"Robert")
    obj.display()

    print("Patient information")
    obj1=Patient()
    obj1.accept1("Alexander")
    obj1.display1()

    print("Appointment time")
    obj2=Appointment()
    obj2.accept2("11 AM")
    obj2.display2()


    ReplyDelete
  15. Program of Hierarchical inheritance for Doctor,patient,Appointment-->>

    class Doctor:
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("Id is"+str(self.id)+"Name is"+str(self.name))

    class Patient(Doctor):
    def accept1(self,name):
    self.name=name
    def display1(self):
    print("Name is"+str(self.name))

    class Appointment(Doctor):
    def accept2(self,time):
    self.time=time
    def display2(self):
    print("Time is"+str(self.time))

    print("Doctor information")
    obj=Doctor()
    obj.accept(420,"Robert")
    obj.display()

    print("Patient information")
    obj1=Patient()
    obj1.accept1("Alexander")
    obj1.display1()

    print("Appointment time")
    obj2=Appointment()
    obj2.accept2("11 AM")
    obj2.display2()


    ReplyDelete
  16. Program of multiple inheritance for Doctor,Patient,Appointment-->>

    class Doctor:
    def fun(self):
    print("Doctor")
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("Id is"+str(self.id)+"Name is"+str(self.name))

    class Patient:
    def fun(self):
    print("Patient")
    def accept1(self,name):
    self.name=name
    def display1(self):
    print("Name is"+str(self.name))

    class Appointment(Doctor,Patient):
    def accept2(self,time):
    self.time=time
    def display2(self):
    print("Time is"+str(self.time))

    print("Doctor information")
    obj=Doctor()
    obj.accept(420,"Robert")
    obj.display()

    print("Patient information")
    obj1=Patient()
    obj1.accept1("Alexander")
    obj1.display1()

    print("Appointment time")
    obj2=Appointment()
    obj2.accept2("11 AM")
    obj2.display2()


    ReplyDelete
  17. Program of Multilevel inheritance of Team,coach,player-->>

    class Team:
    def accept(self,name,country):
    self.name=name
    self.country=country
    def display(self):
    print("Team name is"+str(self.name)+"Team's country is"+str(self.country))

    class Coach:
    def accept1(self,coachname):
    self.coachname=coachname
    def display1(self):
    print("Coach Name is"+str(self.coachname))

    class Player:
    def accept2(self,playerinfo):
    self.playerinfo=playerinfo
    def display2(self):
    print("Player is"+str(self.playerinfo))

    print("Team details")
    obj=Team()
    obj.accept("Deccan chargers","India")
    obj.display()

    print("Coach information")
    obj1=Coach()
    obj1.accept1("Bryan lara")
    obj1.display1()

    print("Player's specialisation")
    obj2=Player()
    obj2.accept2("All rounder")
    obj2.display2()

    ReplyDelete
  18. Program of multilevel inheritance for institute,branch,location-->>

    class Institute:
    def accept(self,institutename,institutetype):
    self.institutename=institutename
    self.institutetype=institutetype
    def display(self):
    print("Institute name is"+str(self.institutename)+"Institute's type is"+str(self.institutetype))

    class Branch:
    def accept1(self,bhopal):
    self.bhopal=bhopal
    def display1(self):
    print("Branch of"+str(self.bhopal))

    class Location:
    def accept2(self,locationinfo):
    self.locationinfo=locationinfo
    def display2(self):
    print("Located at"+str(self.locationinfo))

    print("Institute details")
    obj=Institute()
    obj.accept("SCS","Software training institute")
    obj.display()

    print("Branch name")
    obj1=Branch()
    obj1.accept1("Bhopal")
    obj1.display1()

    print("Location")
    obj2=Location()
    obj2.accept2("Lakeview")
    obj2.display2()

    ReplyDelete
  19. Program of Hierarchical inheritance for Team,coach,player-->>

    class Team:
    def accept(self,name,country):
    self.name=name
    self.country=country
    def display(self):
    print("Team name is"+str(self.name)+"Team's country is"+str(self.country))

    class Coach(Team):
    def accept1(self,coachname):
    self.coachname=coachname
    def display1(self):
    print("Coach Name is"+str(self.coachname))

    class Player(Team):
    def accept2(self,playerinfo):
    self.playerinfo=playerinfo
    def display2(self):
    print("Player is"+str(self.playerinfo))

    print("Team details")
    obj=Team()
    obj.accept("Deccan chargers","India")
    obj.display()

    print("Coach information")
    obj1=Coach()
    obj1.accept1("Don bradman")
    obj1.display1()

    print("Player's specialisation")
    obj2=Player()
    obj2.accept2("All rounder")
    obj2.display2()

    ReplyDelete
  20. Program of Multiple inheritance for Team,coach,player-->>

    class Team:
    def fun(self):
    print("Team")
    def accept(self,name,country):
    self.name=name
    self.country=country
    def display(self):
    print("Team name is"+str(self.name)+"Team's country is"+str(self.country))

    class Coach:
    def fun(self):
    print("coach")
    def accept1(self,coachname):
    self.coachname=coachname
    def display1(self):
    print("Coach Name is"+str(self.coachname))

    class Player(Team,Coach):
    def accept2(self,playerinfo):
    self.playerinfo=playerinfo
    def display2(self):
    print("Player is"+str(self.playerinfo))

    print("Team details")
    obj=Team()
    obj.accept("Deccan chargers","India")
    obj.display()

    print("Coach information")
    obj1=Coach()
    obj1.accept1("Don bradman")
    obj1.display1()

    print("Player's specialisation")
    obj2=Player()
    obj2.accept2("All rounder")
    obj2.display2()

    ReplyDelete
  21. Program of Hierarchical inheritance for Institute,branch,location-->>

    class Institute:
    def accept(self,institutename,institutetype):
    self.institutename=institutename
    self.institutetype=institutetype
    def display(self):
    print("Institute name is"+str(self.institutename)+"Institute's type is"+str(self.institutetype))

    class Branch(Institute):
    def accept1(self,bhopal):
    self.bhopal=bhopal
    def display1(self):
    print("Branch of"+str(self.bhopal))

    class Location(Institute):
    def accept2(self,locationinfo):
    self.locationinfo=locationinfo
    def display2(self):
    print("Located at"+str(self.locationinfo))

    print("Institute details")
    obj=Institute()
    obj.accept("SCS","Software training institute")
    obj.display()

    print("Branch name")
    obj1=Branch()
    obj1.accept1("Bhopal")
    obj1.display1()

    print("Location")
    obj2=Location()
    obj2.accept2("Lakeview")
    obj2.display2()

    ReplyDelete
  22. Program of multiple inheritance for institute,branch,location-->>

    class Institute:
    def fun(self):
    print("Institute")
    def accept(self,institutename,institutetype):
    self.institutename=institutename
    self.institutetype=institutetype
    def display(self):
    print("Institute name is"+str(self.institutename)+"Institute's type is"+str(self.institutetype))

    class Branch:
    def fun(self):
    print("Branch")
    def accept1(self,bhopal):
    self.bhopal=bhopal
    def display1(self):
    print("Branch of"+str(self.bhopal))

    class Location(Institute,Branch):
    def accept2(self,locationinfo):
    self.locationinfo=locationinfo
    def display2(self):
    print("Located at"+str(self.locationinfo))

    print("Institute details")
    obj=Institute()
    obj.accept("SCS","Software training institute")
    obj.display()

    print("Branch name")
    obj1=Branch()
    obj1.accept1("Bhopal")
    obj1.display1()

    print("Location")
    obj2=Location()
    obj2.accept2("Lakeview")
    obj2.display2()

    ReplyDelete
  23. # Check Prime number
    class Prime:
    def accept(self):
    self.n = int(input("Enter number to check Prime"))

    def ope(self):
    self.count = 0
    for i in range(2, (self.n)):

    if (self.n)%i == 0:
    self.count = self.count+1
    def display(self):
    if self.count != 0:
    print(self.n,"Not Prime")
    else:
    print(self.n,"Prime number")


    r= Prime()
    r.accept()
    r.ope()
    r.display()

    ReplyDelete
  24. Jayant Chawliya
    class HomeWork:
    def input_prime(self):
    self.num = int(input("Enter the number here: "))

    def prime(self):
    if self.num > 1:
    for i in range(2, self.num):
    if (self.num % i) == 0:
    print(self.num, "is not a prime number")
    break
    else:
    print(self.num, "is a prime number")

    def diamond_accept(self):
    self.a=int(input("Enter the number of Rows : "))

    def Diamond(self):
    n = 0
    for i in range(1, self.a + 1):
    for j in range(1, (self.a - i) + 1):
    print(end=" ")

    while n != (2 * i - 1):
    print("*", end="")
    n = n + 1
    n = 0
    print()

    k = 1
    n = 1
    for i in range(1, self.a):
    for j in range(1, k + 1):
    print(end=" ")
    k = k + 1
    while n <= (2 * (self.a - i) - 1):
    print("*", end="")
    n = n + 1
    n = 1
    print()
    def marksheet_accept(self):
    self.M=int(input("Enter the marks of maths :"))
    self.J=int(input("Enter the marks of java :"))

    def marksheet(self):

    self.add=self.M+self.J
    print("Total Marks of Maths and Java is ",self.add)

    self.per=self.add/200*100
    print("Percentage ",self.per)

    #Supplementry

    self.s=0
    if (self.M < 33):
    print("supply in Maths")
    self.s+=1
    elif (self.J < 33):
    print("supply in java")
    self.s += 1

    #Grace_concept
    if (self.s <= 1):
    if (self.M <= 30):
    self.M += 3
    print("pass with grace 3 ")
    elif(self.s <= 1):
    if (self.J <= 30):
    self.J += 3
    print("pass with grace 3 ")


    obj=HomeWork()
    obj.input_prime()
    obj.prime()

    obj1=HomeWork()
    obj1.diamond_accept()
    obj1.Diamond()

    obj2=HomeWork()
    obj2.marksheet_accept()
    obj2.marksheet()

    ReplyDelete
  25. Program for prime number?
    class Prime:
    def accept(self,num):
    self.num = num


    def logic(self):
    for i in range(2,self.num):
    if self.num%i==0:
    self.result="not prime"
    break
    else:
    self.result = "prime"

    def display(self):
    print(self.result)



    obj = Prime()
    obj.accept(int(input("enter number")))
    obj.logic()
    obj.display()



    ReplyDelete
  26. Solution of fibonacci series?
    class Fibonacci:
    def accept(self,num):
    self.num = num


    def logic(self):
    a=-1
    b=1
    self.result=''
    for i in range(1,self.num+1):
    c=a+b
    self.result += str(c) + "\n"
    a=b
    b=c


    def display(self):
    print(self.result)



    obj = Fibonacci()
    obj.accept(int(input("enter number of terms to display series")))
    obj.logic()
    obj.display()



    ReplyDelete
  27. #WAP to calculate Simple Interest using static data member only
    class Si:
    p=5000
    r= 4
    t = 2


    r =(Si.p*Si.r*Si.t)/100
    print(r)

    ReplyDelete
  28. #WAP to calculate Simple Interest using dynamic data member only
    class si:
    def accept(self):
    self.p =int(input("Enter Principal amount = "))
    self.r = int(input("Enter interest rate = "))
    self.t = int(input("Enter time period = "))


    def s_i(self):
    self.r = self.p*self.r*self.t/100

    def display(self):
    print("SI is = " + str(self.r))

    b= si()
    b.accept()
    b.s_i()
    b.display()

    ReplyDelete

  29. #Program for prime number?
    class Prime:
    def accept(self,num):
    self.num = num


    def logic(self):
    for i in range(2,self.num):
    if self.num%i==0:
    self.result=("not prime")
    break
    else:
    self.result =("prime")

    def display(self):
    print(self.result)



    obj = Prime()
    obj.accept(int(input("enter number")))
    obj.logic()
    obj.display()

    ReplyDelete
  30. # EXAMPLE MULTI PARAMETER CONSTRUCTER
    class Addition:
    def __init__(self,f,s):
    self.f = f
    self.s = s

    def display(self):
    print("First number is " +str(self.f))
    print("Second number is "+ str(self.s))
    print("Sum is " + str(self.add))
    print("Multiplication = " +str(self.multi))


    def logic(self):
    self.add = self.f + self.s
    self.multi = self.f*self.s
    f =float(input("Enter first number = "))
    s =float(input("Enter second number = "))
    obj = Addition(f,s)
    obj.logic()
    obj.display()

    ReplyDelete
  31. #ATM
    class Bank:
    balance = 50000

    def __bal(self):
    print("Your balance is = " +str(self.balance))

    def __credit(self,amount):
    self.balance += amount
    print("Current balance is = "+str(self.balance))

    def __debit(self,amount):
    self.balance -=amount
    print("Current balance = "+str(self.balance))


    def login(self, pin):
    if pin == 12345:
    print("WELCOME")
    x = input("Press B for balance enquiry. Press D for debit amount. Press C for credit amount = ")
    if x=='b' or x=='B':
    self.__bal()

    if x == 'c' or x=='C':
    self.__credit(int(input("Enter amount to credit")))
    if x == 'd' or x == 'D':
    self.__debit(int(input("Enter amount to withdraw")))
    else:
    print("Incorrect pin")
    pin = int(input("Enter pin"))
    obj = Bank()
    obj.login(pin)

    ReplyDelete
  32. #Star Pattern
    class Star:
    def accept(self):
    self.n= int(input("Enter number of rows= "))

    def display(self):
    for i in range(0,self.n):
    print(' '*(self.n-i-1) + '* '*(i+1))
    for j in range(self.n-1,0,-1):
    print(' '*(self.n-j) + '* '*(j))

    obj= Star()
    obj.accept()
    obj.display()

    ReplyDelete
  33. # Manage Patient, Doctor, and Appointment using all possible Inheritance

    #single inheritance
    class Doctor:
    def doctor(self,name,location):
    self.name=name
    self.location=location
    def display(self):
    print("Doctor Details: ")
    print("Doctor_name : "+str(self.name),"\nlocation : "+str(self.location))

    class Patient(Doctor):
    def patient(self,id,name1,age):
    self.id=id
    self.name1=name1
    self.age=age
    def display1(self):
    print("id is : "+str(self.id),"name : "+str(self.name1),"age: "+str(self.age))

    class Appointement(Patient):
    def appoint(self,time):
    self.time=time
    def display2(self):
    print("time is : "+str(self.time))

    obj=Appointement()
    obj.doctor(" Manish "," Indore " )
    obj.patient(101," Rahul ",40)
    obj.appoint("6 pm")
    obj.display()
    obj.display1()
    obj.display2()

    ReplyDelete
  34. #hierarchical
    class Team:
    def func1(self):
    print("This function is in Team class.")

    def Teaminfo(self, country, group):
    self.country = country
    self.group = group

    def display(self):
    print("country" + str(self.country), "group" + str(self.group))



    class Child1(Team):
    def func2(self):
    print("This function is in child 1.")



    class Child2(Team):
    def func3(self):
    print("This function is in child 2.")



    object1 = Child1()
    object1.func1()
    object1.Teaminfo(" INDIA "," A")
    object1.display()
    object1.func2()

    object2 = Child2()
    object2.func1()
    object2.Teaminfo(" INDIA "," B")
    object2.display()

    ReplyDelete
  35. #Multi-Level Inheritance Example for Area of the circle, triangle, and rectangle:-
    class Areaofcircle:
    def accept(self,a):
    self.a =a

    def logic(self):
    self.r = 3.14 * self.a *self.a
    def display(self):
    print("Area of circle is " +str(self.r))

    class Areaoftriangle(Areaofcircle):
    def accept1(self,b):
    self.b = b
    def logic1(self):
    self.r = self.a *self.b/2
    def display1(self):
    print("Area of triangle is " +str(self.r))

    class Areaofrectangle(Areaoftriangle):
    def logic2(self):
    self.r = self.a*self.b
    def display2(self):
    print("Area of rectangle is " +str(self.r))

    print("For circle")
    obj = Areaofcircle()
    obj.accept(5)
    obj.logic()
    obj.display()

    print("For Triangle")
    obj1 = Areaoftriangle()
    obj1.accept(4)
    obj1.accept1(7)
    obj1.logic1()
    obj1.display1()

    print("For rectangle")
    obj2 = Areaofrectangle()
    obj2.accept(8)
    obj2.accept1(7)
    obj2.logic2()
    obj2.display2()


    ReplyDelete
  36. By Multi-level, Manage Coach, Team, and Player using all possible Inheritance?

    class Coach:
    def accept(self,name):
    self.name=name
    def display(self):
    print("Coach is " +str(self.name))

    class Team(Coach):
    def accept1(self,team):
    self.team = team
    def display1(self):
    print("Team is "+ str(self.team))

    class Player(Team):
    def display2(self):
    print("Player name is " +str(self.name) +" & Player team is "+ str(self.team))

    print("Coach Information")
    obj =Coach()
    obj.accept('Ravi')
    obj.display()

    print("Team Information")
    obj1 =Team()
    obj1.accept('Mukes')
    obj1.accept1('India')
    obj1.display1()

    print("Player Information")
    obj2 =Player()
    obj2.accept('Virat')
    obj2.accept1('India')
    obj2.display2()

    ReplyDelete
  37. #By Multiple Inheritance Manage Coach, Team, and Player using all possible Inheritance?
    class Coach:
    def accept(self,name):
    self.name=name
    def display(self):
    print("Coach is " +str(self.name))

    class Team:
    def accept1(self,team):
    self.team = team
    def display1(self):
    print("Team is "+ str(self.team))

    class Player(Team,Coach):
    def display2(self):
    print("Player name is " +str(self.name) +" & Player team is "+ str(self.team))

    print("Coach Information")
    obj =Coach()
    obj.accept('Ravi Shastri')
    obj.display()

    print("Team Information")
    obj1 =Team()
    obj1.accept1('India')
    obj1.display1()

    print("Player Information")
    obj2 =Player()
    obj2.accept('Virat')
    obj2.accept1('India')
    obj2.display2()

    ReplyDelete
  38. #By Hierarchial inheritance, Manage Coach, Team, and Player using all possible Inheritance?
    class Coach:
    def accept(self,name):
    self.name=name
    def display(self):
    print("Coach is " +str(self.name))

    class Team(Coach):
    def accept1(self,team):
    self.team = team
    def display1(self):
    print("Team is "+ str(self.team))

    class Player(Coach):
    def accept2(self,t):
    self.t = t
    def display2(self):
    print("Player name is " +str(self.name) +" & Player team is "+ str(self.t))

    print("Coach Information")
    obj =Coach()
    obj.accept('Justin Langer')
    obj.display()

    print("Team Information")
    obj1 =Team()
    obj1.accept('Justin Langer')
    obj1.accept1('Australia')
    obj1.display()
    obj1.display1()

    print("Player Information")
    obj2 =Player()
    obj2.accept('Steve Smith')
    obj2.accept2('Australia')
    obj2.display2()

    ReplyDelete
  39. class SI:
    def accept(self,p,r,t):
    self.p=p
    self.r=r
    self.t=t
    def siLogic(self):
    self.si = (self.p*self.r*self.t)/100
    def display(self):
    print("Result is ",self.si)


    obj = SI()
    obj.accept(15000,2,2)
    obj.siLogic()
    obj.display()

    obj1 = SI()
    obj1.accept(45000,2,2)
    obj1.siLogic()
    obj1.display()

    ReplyDelete
  40. Create Product class to manage Product Operation
    class Product:
    def accept(self,pid,pname,price):
    self.pid=pid
    self.pname=pname
    self.price=price

    def display(self):
    print("ID is ",self.pid)
    print("Product Name is ",self.pname)
    print("Product Price is ",self.price)




    p1 = Product()
    p1.accept(1,'Mobile phone',45000)
    p1.display()

    p2 = Product()
    p2.accept(2,'Laptop',55000)
    p2.display()

    ReplyDelete
  41. #ABHISHEK SINGH
    #1) WAP to manage five student records using rno, marks, and age and display max-age and max marks of students?
    class student:

    def getdata(self):
    self.roll=input("\nEnter roll no: ")
    self.marks=int(input("Enter marks: "))
    self.age=int(input("Enter age: "))

    hmarks=0
    hage=0
    roll=''

    for s in range(5):
    s=student()
    s.getdata()
    if hmarks<s.marks:
    hmarks=s.marks
    if hage<s.age:
    hage=s.age


    print("Highest marks: ",hmarks)
    print("Highest age: ",hage)

    ReplyDelete
  42. #ABHISHEK SINGH
    #2) WAP to calculate the prime number, factorial, and Fibonacci series program using #oops with three lasses and three methods (accept, logic,display)
    class Factorial():
    def accept(self):
    flag=True
    while flag:
    try:
    self.num=int(input("\nEnter number for Factorial to be calc: "))
    flag=False
    if self.num<0:
    print("Number cannot be negative !")
    flag=True
    except:
    print("Wrong Input ! Try Again ")
    flag=True

    def logic(self):
    self.f=1
    if self.num>1:
    for i in range(2,self.num+1):
    self.f*=i

    def display(self):
    print("Factoril is: ",self.f)

    class Fibonacci:

    def accept(self):
    flag=True
    while flag:
    try:
    self.num=int(input("\nEnter Range for Fibonnacci Series: "))
    flag=False
    except:
    print("Invalid Input! Try again")
    flag=True

    def logic(self):

    #0,1,2,3,5,8,13,21
    self.lst=[]
    count=0
    p=0
    c=1
    self.lst.append(p)
    self.lst.append(c)
    if self.num>2:
    while count1):
    for i in range(2,self.num):
    if self.num%i==0:
    self.prime=False
    break


    def display(self):
    if self.prime:
    print("Prime Number")
    else:
    print("Not Prime")

    f1=Factorial()
    f1.accept()
    f1.logic()
    f1.display()

    fb1=Fibonacci()
    fb1.accept()
    fb1.logic()
    fb1.display()

    p1=Prime()
    p1.accept()
    p1.logic()
    p1.display()


    ReplyDelete
  43. #parth
    class studentrecords:

    def getinfo(self):
    self.rollnumber=input("\nEnter rollnumber: ")
    self.marks=int(input("Enter marks: "))
    self.age=int(input("Enter age: "))

    marks=0
    hage=0
    rollnumber=''

    for s in range(5):
    s= studentrecords()
    s.getinfo()
    if marks<s.marks:
    marks=s.marks
    if hage<s.age:
    hage=s.age


    print("Highest marks: ",marks)
    print("Highest age: ",hage)

    ReplyDelete
  44. #parth
    #student record
    class Student:
    def accept(self,rno,sname,branch,fees):
    self.rno=rno
    self.sname=sname
    self.branch=branch
    self.fees=fees

    def display(self):
    print("RollNo is "+str(self.rno) + " Name is "+self.sname + " Branch is " + self.branch +" Fees is "+str(self.fees));

    obj = Student()
    obj.accept(4002655,"PARTH","CS",45000)
    obj.display()

    obj1 = Student()
    obj1.accept(4005688,"ALEX","IT",50000)
    obj1.display()

    ReplyDelete
  45. #wap prime no using oops apply three Methods (accept,logic & display)
    class prime():
    def getNo (self,num):
    self.num=num
    def isprime(self):
    self.result=""
    for i in range(2,num+1):
    if num%i==0:
    self.result="not prime"
    break
    else:
    self.result="prime"
    def display(self):
    print(self.result)
    num=int(input("Enter the Number = "))
    obj=prime()
    obj.getNo(num)
    obj.isprime()
    obj.display()
    >>>Doubt Not given Exect Result

    ReplyDelete
  46. #wap factorial using oops
    class fact():
    def getNo(self,num):
    self.num=num
    def Logic(self):
    f=1
    self.r=""
    for i in range (self.num,1,-1):
    f=f*i
    else:
    self.r="Result of Factorial is = "+str(f)
    def display(self):
    print(self.r)
    num=int(input("Enter the Number = "))
    f1=fact()
    f1.getNo(num)
    f1.Logic()
    f1.display()

    #wap Fabonacci Series using oops

    class fab():
    def accept(self,num):
    self.num=num
    def logic(self):
    a=-1
    b=1
    self.r=""
    for i in range(1,self.num+1):
    c=a+b
    self.r+=str(c) +"\n"
    a=b
    b=c
    def display(self):
    print(self.r)
    num=int(input("Enter the Number "))
    obj=fab()
    obj.accept(num)
    obj.logic()
    obj.display()

    ReplyDelete
  47. class student:
    def accept(self):
    self.rln=input("\nEnter rollno: ")
    self.marks=int(input("Enter marks: "))
    self.age=int(input("Enter age: "))

    smarks=0
    sage=0
    rollno=''

    for s in range(5):
    s= student()
    s.accept()
    if smarks<s.marks:
    smarks=s.marks
    if sage<s.age:
    sage=s.age


    print("Highest marks: ",smarks)
    print("Highest age: ",sage)

    ReplyDelete
  48. #parth
    class number:
    def __init__(self,a,b):
    self.a=a
    self.b=b
    def add(self):
    print("result is "+str(self.a+self.b))
    def sub(self):
    print("result is "+str(self.a-self.b))
    def mult(self):
    print("result is "+str(self.a*self.b))
    def div(self):
    print("result is "+str(self.a/self.b))
    def __del__(self):
    print("Destructor will be called")

    obj = number(20,10)
    obj.add()
    obj.sub()
    obj.mult()
    obj.div()

    ReplyDelete
  49. #parth
    #data encapsulation
    class data:

    a=500
    def data1(self):
    a=20
    print(A.a)
    print(a)
    self.a=100
    def data2(self):
    print(self.a)
    print(A.a)


    obj = data()
    obj.data1()
    obj.data2()

    ReplyDelete
  50. #real life example of data abstraction
    #parth
    class Car:
    def mileage(self):
    pass

    class Tesla(Car):
    def mileage(self):
    print("The mileage is 30kmph")
    class Suzuki(Car):
    def mileage(self):
    print("The mileage is 25kmph ")
    class Duster(Car):
    def mileage(self):
    print("The mileage is 24kmph ")

    class Renault(Car):
    def mileage(self):
    print("The mileage is 27kmph ")
    c=Car()

    t= Tesla ()
    t.mileage()

    r = Renault()
    r.mileage()

    s = Suzuki()
    s.mileage()

    d = Duster()
    d.mileage()

    ReplyDelete
  51. #real life example of data abtraction
    class Polygon:
    def sides(self):
    pass
    class Triangle(Polygon):
    def sides(self):
    print("Triangle has 3 sides")
    class Pentagon(Polygon):
    def sides(self):
    print("Pentagon has 5 sides")
    class Hexagon(Polygon):
    def sides(self):
    print("Hexagon has 6 sides")
    class square(Polygon):
    def sides(self):
    print("I have 4 sides")
    p=Polygon()

    t = Triangle()
    t.sides()

    s = square()
    s.sides()

    p = Pentagon()
    p.sides()

    h = Hexagon()
    h.sides()

    ReplyDelete
  52. #Overload + operator to convert dollar to rs and rs to dollar in a single program?
    class Option:
    def __init__(self,num):
    self.num=num
    def __add__(self,other):
    return f"""Convert to dollar to rs {Option((self.num + other.num)*75)}
    Convert to rs to dollar {Option((self.num+other.num)/75)}"""
    def __str__(self):
    return str(self.num)
    obj=Option(10)
    obj1=Option(20)

    obj2=obj+obj1
    print(obj2)

    ReplyDelete
  53. #Overload / and // operator?

    class Division:
    def __init__(self,num):
    self.num=num
    def __truediv__(self,other):
    return f" Result True Division {Division(self.num//other.num)}"
    def __floordiv__(self,div):
    return f" Result Floor Division {Division(self.num/div.num)}"
    def __str__(self):
    return str(self.num)
    obj=Division(100)
    obj1=Division(20)
    obj2=Division(300)
    obj3=Division(40)
    obj4=obj/obj1
    obj5=obj2//obj3
    print(obj4)
    print(obj5)

    ReplyDelete
  54. #Overload * the operator, multiply the result with GST?

    class Gst:
    def __init__(self,rate):
    self.rate=rate
    def __mul__(self,other):
    return f" Result Gold Gst {Gst((self.rate * other.rate)/100)}"
    def __str__(self):
    return str(self.rate)
    obj=Gst(25000)
    obj1=Gst(3)
    obj2=obj*obj1
    print(obj2)

    ReplyDelete
  55. class Corona1:
    def Fever(self):
    print("1.High Fever Approx 200 or 300")

    def Cough(self):
    print("2.Dry Cough")
    print("3.Sore throat")

    def Cold(self):
    print("4.Common Cold")

    def Breath(self):
    print("Shortness of breath")
    def Pain(self):
    print("6.A splitting headache")


    class Corona2(Corona1):
    def Fever(self):
    print("1.High Fever Approx 200 or 300 with Skin rashes")

    def Cough(self):
    print("2.Dry Cough")
    print("3.Sore throat")

    def Cold(self):
    print("4.Common Cold and Diarrhea")

    def Breath(self):
    print("Shortness of breath and Oxygen deficiency ")
    def Pain(self):
    print("6.A splitting headache and Muscle aches")
    print("Old Symptoms of Covid 1.0")
    print()
    obj = Corona1()
    obj.Fever()
    obj.Cough()
    obj.Cold()
    obj.Breath()
    print()
    print("New Symptoms of Covid 2.0")
    print()
    obj = Corona2()
    obj.Fever()
    obj.Cough()
    obj.Cold()
    obj.Breath()
    obj.Pain()

    ReplyDelete
  56. #ABHISHEK SINGH
    #Overload + operator to convert dollar to rs and rs to dollar in a single program?
    class Currencyconv:

    def __init__(self,amt,currency):
    self.amt=amt
    self.currency=currency

    def __add__(self,other):
    if self.currency==other.currency:
    if self.currency=='$':
    return Currencyconv( (self.amt+other.amt)*80 , "Rs" )
    elif self.currency=='Rs':
    return Currencyconv( int((self.amt+other.amt)/80), "$")
    else:
    return Currencyconv(0,"unknown")
    else:
    return Currencyconv(0,"unknown")

    a=Currencyconv(1,'$')
    b=Currencyconv(2,'$')
    c=a+b
    print(c.currency,c.amt)

    ReplyDelete
  57. #ABHISHEK SINGH
    #CORONA OVERRIDING
    class Corona:

    def version(self):
    print("Corona Ver 1.0")
    print("Shortness of Breathing")
    print("Cough")


    class NewCorona(Corona):

    def version(self):
    print("Corona Ver 2.0")
    print("Any Body Problem. You are Covid+ve.")



    virus=NewCorona()

    virus.version()

    ReplyDelete
  58. #ABHISHEK SINGH
    #FLOOR, TRUE DIV OVERLOADING
    class Overloading():

    def __init__(self,num):
    self.num=num

    def __truediv__(self,other):
    return (self.num//other.num)

    def __floordiv__(self,other):
    return (self.num/other.num)



    num1=Overloading(11)
    num2=Overloading(2)


    print(num1/num2)
    print(num1//num2)

    ReplyDelete
  59. #ABHISHEK SINGH
    #MULTIPLICATION OVERLOADING WITH ADDED GST
    class Operatoroverload():

    def __init__(self,num):
    self.num=num


    def __mul__(self,other):
    return (self.num+other.num)*1.18




    a=Operatoroverload(5)
    b=Operatoroverload(10)

    print(a*b)

    ReplyDelete
  60. SACHIN GAUTAM

    #Operater overloading........................................................................

    class currency:
    def __init__(self,Currency):

    self.Currency = Currency

    def __add__(self,other):

    return currency((self.Currency + self.Currency)*80)

    def __mul__(self,other):

    return currency((self.Currency + self.Currency)/80)

    def __str__(self):

    return str(self.Currency)
    obj= currency(50)
    obj1= currency(40)
    obj2= obj+obj1
    obj3= obj*obj1
    print(obj2)
    print(obj3)

    ReplyDelete
  61. SACHIN GAUTAM

    #Floor and True Division....................................................................

    class Division:

    def __init__(self,div):

    self.div=div

    def __truediv__(self,other):

    return (self.div//other.div)

    def __floordiv__(self,other):

    return (self.div/other.div)
    def __str__(self):
    return str(self.div)

    obj1=Division(10)
    obj2=Division(2)
    print("This is True Division ")
    print(obj1//obj2)
    print("This is floor Division")
    print(obj1/obj2)


    ReplyDelete
  62. #parth
    #Multilevel Inheritance
    class Admin:
    def accept(self,id,name):
    self.id=id
    self.name=name

    def display(self):
    print("ID is "+str(self.id)+" name is "+str(self.name))

    class Employee(Admin):
    def accept1(self,sal):
    self.sal=sal
    def display1(self):
    print("Salary is "+str(self.sal))


    class Otherstaff(Employee):
    def accept2(self,bonus):
    self.bonus=bonus
    def display2(self):
    print("Bonus is "+str(self.bonus))

    print("Employee Information")
    obj = Employee()
    obj.accept(34563,"emp")
    obj.accept1(48000)
    obj.display()
    obj.display1()

    print("Admin Info")
    obj1 = Admin()
    obj1.accept(67788,"admin")
    obj1.display()

    print("Other Staff Info")
    obj2 = Otherstaff()
    obj2.accept(23423,"otherstaff")
    obj2.accept1(48000)
    obj2.accept2(1000)
    obj2.display()
    obj2.display1()

    obj2.display2()

    ReplyDelete
  63. #parth
    #GST
    class Gst:
    def __init__(self,rate):
    self.rate=rate
    def __mul__(self,other):
    return f" gst rate of diamond {Gst((self.rate * other.rate)/100)}"
    def __str__(self):
    return str(self.rate)
    obj= Gst(7102)
    obj1= Gst(3)
    obj2= obj * obj1
    print(obj2)

    ReplyDelete
  64. #parth
    #function orverriding
    class Exam:
    def ExamDuration(self):
    print("3 Hours")

    def ExamPattern(self):
    print("Number System")

    def ExamMode(self):
    print("Offline")

    def Syllabus(self):
    print("Outdated")


    class ExamNew(Exam):
    def ExamPattern(self):
    print("Grade System")

    def ExamMode(self):
    print("ONLINE")


    obj = ExamNew()
    obj.ExamDuration()
    obj.ExamPattern()
    obj.ExamMode()
    obj.Syllabus()

    ReplyDelete
  65. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    # Single inheritance
    import datetime
    class Patient:
    def patientinfo(self,name,location):
    self.name=name
    self.location=location
    def Display1(self):
    print("Name : ",(self.name),"\nLocation : ",self.location)
    class Doctor(Patient):
    def doctorInfo(self,Speciallity):
    self.Speciallity=Speciallity
    def Display2(self):
    print("Speciallity : ",(self.Speciallity))
    class Appointement():
    def BookedAppointement(self):
    self.datetime_object=datetime.datetime.now()
    def Display3(self):
    print("Date & Time: ",(self.datetime_object))
    print("**Doctor Details**")
    print("------------------------------------")
    d1=Doctor()
    d1.doctorInfo('Neurologist')
    d1.patientinfo('Dr.Abhay Bhagwat','Indore')
    d1.Display1()
    d1.Display2()
    print("-----------------------------------------")
    d2=Doctor()
    d2.patientinfo('Dr.A Suresh','Indore')
    d2.doctorInfo('Cardiologist')
    d2.Display1()
    d2.Display2()
    print("------------------------------------")
    operation = input("""press 1 for Neurologist
    press 2 for Cardiologist = """)
    print()
    if(operation =='1'):
    d1.Display1()
    d1.Display2()
    elif(operation =='2'):
    d2.Display1()
    d2.Display2()
    print("------------------------------------")
    print("**Patient's Information**")
    print("------------------------------------")
    d1.patientinfo('kishu','jabalpur')
    d1.Display1()
    print("------------------------------------")
    d2.patientinfo('kajal','indore')
    d2.Display1()
    print("------------------------------------")
    print("**Booked Appointement**")
    print("------------------------------------")
    a1=Appointement()
    a1.BookedAppointement()
    a1.Display3()



    ReplyDelete
  66. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    # Multilevel inheritance
    import datetime
    class Patient:
    def patientinfo(self,name,ID,locality):
    self.name=name
    self.ID=ID
    self.locality=locality
    def Display1(self):
    print("Name : ",self.name,"\nID : ",(self.ID),"\nLocality : ",(self.locality))
    class Doctor(Patient):
    def doctorInfo(self,Speciallity):
    self.Speciallity=Speciallity
    def Display2(self):
    print("Speciallity : ",(self.Speciallity),)
    class Appointement(Doctor):
    def BookedAppointement(self):
    self.datetime_object=datetime.datetime.now()
    def Display3(self):
    print("Date & Time: ",(self.datetime_object))
    print("**Doctor's Details**")
    print()
    d1=Doctor()
    d1.doctorInfo('Neurologist')
    d1.patientinfo('Dr.Abhay Bhagwat','D1023','Indore')
    d1.Display1()
    d1.Display2()
    print()
    d2=Doctor()
    d2.doctorInfo('Cardiologist')
    d2.patientinfo('Dr.A Suresh','D2052','Indore')
    d2.Display1()
    d2.Display2()
    print()
    operation = input("""press 1 for Neurologist
    press 2 for Cardiologist = """)
    print()
    if(operation =='1'):
    d1.Display2()
    elif(operation =='2'):
    d2.Display2()
    print()
    print("**Patient's Information**")
    print()
    d1.patientinfo('amit','P150','jabalpur')
    d1.Display1()
    print()
    print("**Booked Appointement**")
    print()
    a1=Appointement()
    a1.BookedAppointement()
    a1.Display3()



    ReplyDelete
  67. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    # Hierarchical inheritance
    import datetime
    class Patient:
    def patientinfo(self,name,ID,locality):
    self.name=name
    self.ID=ID
    self.locality=locality
    def Display1(self):
    print("Name : ",self.name,"\nID : ",(self.ID),"\nLocality : ",(self.locality))
    class Doctor(Patient):
    def doctorInfo(self,Speciallity):
    self.Speciallity=Speciallity
    def Display2(self):
    print("Speciallity : ",(self.Speciallity))
    class Appointement(Patient):
    def BookedAppointement(self):
    self.datetime_object=datetime.datetime.now()
    def Display3(self):
    print("Date & Time: ",(self.datetime_object))
    print("**Doctor's Details**")
    print()
    d1=Doctor()
    d1.doctorInfo('Neurologist')
    d1.patientinfo('Dr.Abhay Bhagwat','D2053','Indore')
    d1.Display1()
    d1.Display2()
    d2=Doctor()
    d2.doctorInfo('Cardiologist')
    d2.patientinfo('Dr.A Suresh','D5423','Indore')
    d2.Display1()
    d2.Display2()
    operation = input("""press 1 for Neurologist
    press 2 for Cardiologist = """)
    print()
    if(operation =='1'):
    d1.Display1()
    elif(operation =='2'):
    d2.Display2()
    print("**Patient's Information**")
    d2.patientinfo('kishan','P536','Jabalpur')
    d2.Display1()
    print("**Booked Appointement**")
    d1=Appointement()
    d1.BookedAppointement()
    d1.Display3()




    ReplyDelete
  68. #Manage Patient, Doctor, and Appointment using all possible Inheritance?
    # Multipleinheritance
    import datetime
    class Appointement:
    def BookedAppointement(self):
    self.datetime_object=datetime.datetime.now()
    def Display1(self):
    print("Date & Time: ",(self.datetime_object))
    class Patient:
    def patientinfo(self,name,ID,locality):
    self.name=name
    self.ID=ID
    self.locality=locality
    def Display2(self):
    print("Name : ",self.name,"\nID : ",(self.ID),"\nLocality : ",(self.locality))
    class Doctor(Appointement,Patient):
    def doctorInfo(self,Speciallity):
    self.Speciallity=Speciallity
    def Display3(self):
    print("Speciallity : ",(self.Speciallity),)
    print("**Doctor's Details**")
    print()
    d1=Doctor()
    d1.doctorInfo('Neurologist')
    d1.patientinfo('Dr.Abhay Bhagwat','D5426','Indore')
    d1.Display2()
    d1.Display3()
    d2=Doctor()
    d2.doctorInfo('Cardiologist')
    d2.patientinfo('Dr.A Suresh','D4582','Indore')
    d2.Display2()
    d2.Display3()
    operation = input("""press 1 for Neurologist
    press 2 for Cardiologist = """)
    print()
    if(operation =='1'):
    d1.Display2()
    d2.Display3()
    elif(operation =='2'):
    d2.Display2()
    d2.Display3()
    print()
    print("**Patient's Information**")
    d1.patientinfo('kishan','P542','Bhopal')
    d1.Display2()
    print("**Booked Appointement**")
    d1.BookedAppointement()
    d1.Display1()


    ReplyDelete
  69. #Manage Coach, Team, and Player using all possible Inheritance?
    # Single Inheritance
    class Team:
    def teaminfo(self,nation):
    self.nation=nation
    def Display1(self):
    print("Nation = ",self.nation)
    class Coach():
    def coachinfo(self,name,age):
    self.name=name
    self.age=age
    def Display2(self):
    print("Name = ",self.name , "\nAge = ",self.age)
    class Players(Coach):
    def playersinfo(self,id):
    self.id=id
    def Display3(self):
    print("ID =",self.id)
    print("**Team Name**")

    t1=Team()
    t1.teaminfo('India')
    t1.Display1()

    p1=Players()
    print("**Coach Details**")

    p1.coachinfo('misham',33)
    p1.Display2()
    print("**Players Details**")

    p1.playersinfo(101)
    p1.coachinfo('karan',25)
    p1.Display3()
    p1.Display2()
    print()
    p1.playersinfo(102)
    p1.coachinfo('virat',23)
    p1.Display3()
    p1.Display2()
    print()
    p1.playersinfo(103)
    p1.coachinfo('hardik',29)
    p1.Display3()
    p1.Display2()









    ReplyDelete
  70. #Manage Coach, Team, and Player using all possible Inheritance?
    # Multilevel Inheritance
    class Coach:
    def coachinfo(self,name,age,nation):
    self.name=name
    self.age=age
    self.nation=nation
    def Display2(self):
    print("Name = " + str(self.name ), "\nAge = "+str(self.age), "\nNation= "+str(self.nation))
    class Players(Coach):
    def playersinfo(self,id):
    self.id=id
    def Display3(self):
    print("ID =",self.id)
    class Team(Players):
    def teaminfo(self,team):
    self.team=team
    def Display1(self):
    print("Team = ",self.team)
    p1=Players()
    print("**Coach Details**")
    p1.coachinfo('misham',33,'India')
    p1.Display2()
    print("**Players Details**")
    p1.playersinfo(101)
    p1.coachinfo('karan',21,'India')
    p1.Display3()
    p1.Display2()
    p1.playersinfo(102)
    p1.coachinfo('virat',25,'India')
    p1.Display3()
    p1.Display2()
    p1.playersinfo(103)
    p1.coachinfo('hardik',28,'India')
    p1.Display3()
    p1.Display2()
    print("**Team Name**")
    t1=Team()
    t1.teaminfo('Royal Challengers')
    t1.Display1()









    ReplyDelete
  71. #Manage Coach, Team, and Player using all possible Inheritance?
    # Hierarchical Inheritance
    class Coach:
    def coachinfo(self,name,age,nation):
    self.name=name
    self.age=age
    self.nation=nation
    def Display2(self):
    print("Name = " + str(self.name ), "\nAge = "+str(self.age), "\nNation= "+str(self.nation))
    class Players(Coach):
    def playersinfo(self,id):
    self.id=id
    def Display3(self):
    print("ID =",self.id)
    class Team(Coach):
    def teaminfo(self,team):
    self.team=team
    def Display1(self):
    print("Team = ",self.team)
    print("**Coach Details**")
    p1=Players()
    p1.coachinfo('misham',33,'India')
    p1.Display2()
    p1.playersinfo(101)
    p1.coachinfo('karan',21,'india')
    p1.Display3()
    p1.Display2()
    print("**Team Name**")
    t1=Team()
    t1.teaminfo('Royal Chanllgers')
    t1.Display1()










    ReplyDelete
  72. #Manage Coach, Team, and Player using all possible Inheritance?
    # Multiple Inheritance
    class Coach:
    def coachinfo(self,name,age,nation):
    self.name=name
    self.age=age
    self.nation=nation
    def Display2(self):
    print("Name = " + str(self.name ), "\nAge = "+str(self.age), "\nNation= "+str(self.nation))
    class Players:
    def playersinfo(self,id):
    self.id=id
    def Display3(self):
    print("ID =",self.id)
    class Team(Coach,Players):
    def teaminfo(self,team):
    self.team=team
    def Display1(self):
    print("Team = ",self.team)
    print("**Team Name**")
    t1=Team()
    t1.teaminfo('Royal Chanllgers')
    t1.Display1()
    print("**Coach Details**")
    t1.coachinfo('misham',33,'India')
    t1.Display2()
    t1.playersinfo(101)
    t1.coachinfo('karan',21,'india')
    t1.Display3()
    t1.Display2()











    ReplyDelete
  73. # Manage Branch, Location, and Institute using all possible Inheritance
    # Multiple Inheritance
    class Branch:
    def branchinfo(self,Name,Branch):
    self.Name=Name
    self.Branch=Branch
    def Display1(self):
    print("Name = "+str(self.Name),"\nBranch = "+str(self.Branch))
    class Institute:
    def instituteinfo(self,InstituteName):
    self.InstituteName=InstituteName
    def Display2(self):
    print("InstituteName = " + str(self.InstituteName ))
    class Location(Institute,Branch):
    def locationinfo(self,Location):
    self.Location=Location
    def Display3(self):
    print("Location= "+str(self.Location))

    L1=Location()
    print("**Institute Name**")
    L1.instituteinfo('Indian Institute of Management')
    L1.Display2()
    print()
    print("**Institute Location**")
    L1.locationinfo('Indore')
    L1.Display3()

    print("\n**Student Details**")
    L1.branchinfo('Karan','cs')
    L1.Display1()
    L1.Display2()
    L1.Display3()
    print()
    L1.branchinfo('amita','IT')
    L1.Display1()
    L1.Display2()
    L1.Display3()











    ReplyDelete
  74. # Manage Branch, Location, and Institute using all possible Inheritance
    # Hierarchical inheritance
    class Branch:
    def branchinfo(self,Name,Branch):
    self.Name=Name
    self.Branch=Branch
    def Display1(self):
    print("Name = "+str(self.Name),"\nBranch = "+str(self.Branch))
    class Institute(Branch):
    def instituteinfo(self,InstituteName):
    self.InstituteName=InstituteName
    def Display2(self):
    print("InstituteName = " + str(self.InstituteName ))
    class Location(Branch):
    def locationinfo(self,Location):
    self.Location=Location
    def Display3(self):
    print("Location= "+str(self.Location))

    L1=Institute()
    print("**Institute Name**")
    L1.instituteinfo('Indian Institute of Management')
    L1.Display2()
    print()
    print("**Institute Location**")
    L2=Location()
    L2.locationinfo('Indore')
    L2.Display3()

    print("\n**Student Details**")
    L1.branchinfo('Karan','cs')
    L1.Display1()
    L1.Display2()
    L2.Display3()
    print()
    L2.branchinfo('amita','IT')
    L2.Display1()
    L1.Display2()
    L2.Display3()












    ReplyDelete
  75. # Manage Branch, Location, and Institute using all possible Inheritance
    # Hierarchical inheritance
    class Branch:
    def branchinfo(self,Name,Branch):
    self.Name=Name
    self.Branch=Branch
    def Display1(self):
    print("Name = "+str(self.Name),"\nBranch = "+str(self.Branch))
    class Institute(Branch):
    def instituteinfo(self,InstituteName):
    self.InstituteName=InstituteName
    def Display2(self):
    print("InstituteName = " + str(self.InstituteName ))
    class Location(Branch):
    def locationinfo(self,Location):
    self.Location=Location
    def Display3(self):
    print("Location= "+str(self.Location))

    L1=Institute()
    print("**Institute Name**")
    L1.instituteinfo('Indian Institute of Management')
    L1.Display2()
    print()
    print("**Institute Location**")
    L2=Location()
    L2.locationinfo('Indore')
    L2.Display3()

    print("\n**Student Details**")
    L1.branchinfo('Karan','cs')
    L1.Display1()
    L1.Display2()
    L2.Display3()
    print()
    L2.branchinfo('amita','IT')
    L2.Display1()
    L1.Display2()
    L2.Display3()












    ReplyDelete
  76. #Single Inheritance
    class Admin:
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("ID : ",self.id,"Name : ",self.name)
    class Employee(Admin):
    def accept1(self,sal):
    self.sal=sal
    def display1(self):
    print("sal : ",self.sal)
    print("Employee Information")
    obj=Employee()
    obj.accept(102,'neha')
    obj.accept1(12000)
    obj.display()
    obj.display1()
    print("Admin Information")
    obj1=Admin()
    obj1.accept(105,'sneha')
    obj.display()

    ReplyDelete
  77. #Multilevel Inheritance
    class Admin:
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("ID : ",self.id,"Name : ",self.name)
    class Employee(Admin):
    def accept1(self,sal):
    self.sal=sal
    def display1(self):
    print("sal : ",self.sal)
    class OtherStaff(Employee):
    def accept2(self,bonus):
    self.bonus=bonus
    def display2(self):
    print("Bonus : ",self.bonus)

    print("Admin Information")

    obj1=Admin()
    obj1.accept(105,'sneha')
    obj1.display()
    print("Employee Information")

    obj=Employee()
    obj.accept(102,'neha')
    obj.accept1(12000)
    obj.display()
    obj.display1()

    print("OtherStaff Info")
    obj2 = OtherStaff()
    obj2.accept(1002,"kittu")
    obj2.accept1(10500)
    obj2.accept2(200)
    obj2.display()
    obj2.display1()
    obj2.display2()





    ReplyDelete
  78. #Hierarchical Inheritance
    class Admin:
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("ID : ",self.id,"Name : ",self.name)
    class Employee(Admin):
    def accept1(self,sal):
    self.sal=sal
    def display1(self):
    print("sal : ",self.sal)
    class OtherStaff(Admin):
    def accept2(self,bonus):
    self.bonus=bonus
    def display2(self):
    print("Bonus : ",self.bonus)

    print("Admin Information")

    obj1=Admin()
    obj1.accept(105,'sneha')
    obj1.display()
    print("Employee Information")

    obj=Employee()
    obj.accept(102,'neha')
    obj.accept1(12000)
    obj.display()
    obj.display1()

    print("OtherStaff Info")
    obj2 = OtherStaff()
    obj2.accept(1002,"kittu")
    obj2.accept2(200)
    obj2.display()
    obj2.display2()





    ReplyDelete
  79. #Multiple Inheritance
    class Admin:
    def accept(self,id,name):
    self.id=id
    self.name=name
    def display(self):
    print("ID : ",self.id,"Name : ",self.name)
    class Employee:
    def accept1(self,sal):
    self.sal=sal
    def display1(self):
    print("sal : ",self.sal)
    class OtherStaff(Employee,Admin):
    def accept2(self,bonus):
    self.bonus=bonus
    def display2(self):
    print("Bonus : ",self.bonus)

    print("Admin Information")

    obj1=Admin()
    obj1.accept(105,'sneha')
    obj1.display()
    print("Employee Information")

    obj=Employee()
    obj.accept1(12000)
    obj.display1()

    print("OtherStaff Info")
    obj2 = OtherStaff()
    obj2.accept(1002,"kittu")
    obj2.accept1(12000)
    obj2.accept2(200)
    obj2.display()
    obj2.display1()
    obj2.display2()





    ReplyDelete
  80. class Circle:
    def accept(self,a):
    self.a=a
    def dis(self):
    print("Area Of Circle : ",(3.14*self.a*self.a))
    class Triangle(Circle):
    def accept1(self,b):
    self.b=b
    def dis1(self):
    print("Area Of Triangle : ",((self.a*self.b)/2))
    class Ract(Triangle):
    def accept2(self):
    self.area=self.a*self.b
    def dis2(self):
    print("Area Of Ractangle : ",self.area)
    a1=Circle()
    a1.accept(5)
    a1.dis()

    a2=Triangle()
    a2.accept(5)
    a2.accept1(10)
    a2.dis1()

    a3=Ract()
    a3.accept(12)
    a3.accept1(8)
    a3.accept2()
    a3.dis2()

    ReplyDelete
  81. class Student:
    def __init__(self,name):
    self.name=name

    def __str__(self):
    return str(self.name)

    ReplyDelete
  82. #call Module class
    #import moduleclass.py
    from moduleclass import Student

    obj = Student('rohit')
    print(obj)

    ReplyDelete
  83. #using Destructor In Filehandling
    class test:
    def __init__(self):
    self.f = open("demo.txt","w+")
    def write(self):
    title = input("Enter title")
    self.f.write("\n"+title)
    desc = input("Write content")
    self.f.write("\n"+desc)
    def __del__(self):
    self.f.close()
    print("Destructor called file closed")

    t = test()
    t.write()
    test()

    ReplyDelete
  84. # Manage Branch, Location, and Institute using all possible Inheritance
    #parth
    class Branch:
    def branchinfo(self,Name,Branch):
    self.Name=Name
    self.Branch=Branch
    def Display1(self):
    print("Name = "+str(self.Name),"\nBranch = "+str(self.Branch))
    class Institute(Branch):
    def instituteinfo(self,InstituteName):
    self.InstituteName=InstituteName
    def Display2(self):
    print("InstituteName = " + str(self.InstituteName ))
    class Location(Branch):
    def locationinfo(self,Location):
    self.Location=Location
    def Display3(self):
    print("Location= "+str(self.Location))

    L1=Institute()
    print("Institute Name")
    L1.instituteinfo('Makhanlal Chaturvedi University')
    L1.Display2()
    print()
    print("Institute Location")
    L2=Location()
    L2.locationinfo('Bhopal')
    L2.Display3()

    print("\nStudent Details")
    L1.branchinfo('Parth','BCA')
    L1.Display1()
    L1.Display2()
    L2.Display3()
    print()
    L2.branchinfo('Alex','CS')
    L2.Display1()
    L1.Display2()
    L2.Display3()

    ReplyDelete
  85. #parth
    #Manage Coach, Team, and Player using all possible Inheritance
    class Coach:
    def coachinfo(self,name,age,nation):
    self.name=name
    self.age=age
    self.nation=nation
    def Display2(self):
    print("Name = " + str(self.name ), "\nAge = "+str(self.age), "\nNation= "+str(self.nation))
    class Players:
    def playersinfo(self,id):
    self.id=id
    def Display3(self):
    print("ID =",self.id)
    class Team(Coach,Players):
    def teaminfo(self,team):
    self.team=team
    def Display1(self):
    print("Team = ",self.team)
    print("Team Name")
    t1=Team()
    t1.teaminfo('Assassins')
    t1.Display1()
    print("Coach Details")
    t1.coachinfo('Alex',33,'India')
    t1.Display2()
    t1.playersinfo(101)
    t1.coachinfo('Alph',21,'india')
    t1.Display3()
    t1.Display2()

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post