OOPS in Python

184


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()
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.

class Student:
    def Accept(self,rno,sname):
        self.rno=rno
        self.sname=sname
    def Display(self):
        print("Rno is ",self.rno," Name is ",self.sname)
obj = Student()
obj.Accept(1001,"Manish")
obj.Display()
obj1 = Student()
obj1.Accept(1002,"Danish")
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()
Class with Object List:-
class Student:
    def accept(self,rno,sname,branch,fee):
        self.rno=rno
        self.sname=sname
        self.branch=branch
        self.fee=fee
    def display(self):
        print("rno is "+ str(self.rno)+ " name is "+self.sname+ " branch is "+self.branch + " fees is "+str(self.fee))
'''obj = Student()
obj.accept(1001,"xyz","CS",45000)    
obj.display()        

obj1 = Student()
obj1.accept(1002,"abc","CS",35000)    
obj1.display()  '''
obj = []
item = int(input("Enter number of students"))
for i in range(item):
    o = Student()
    o.accept(int(input("enter rno")),input("name"),input("branch"),int(input("fees")))
    obj.append(o)
    
for i in range(item):
    obj[i].display()
    Assignment:-
1)  WAP to manage five student records using rno, marks, and age and display max-age and max marks of students?
Solution:-
class Student:
    def accept(self,rno,marks,age):
        self.rno=rno
        self.marks=marks
        self.age=age
    def display(self):
        print("rno is "+str(self.rno) + "marks is "+str(self.marks) + "age is "+str(self.age))
obj = []
for i in range(0,2):
     o= Student()
     o.accept(int(input("Enter rno")),int(input("Enter marks")),int(input("Enter Age")))
     obj.append(o)

print(len(obj))
mx=0
             
for i in range(0,2):
       if mx<obj[i].marks:
              mx = obj[i].marks
else:
    print("Maximum mark is ",mx)
   
2)  WAP to calculate the prime number, factorial, and Fibonacci series program using oops with three classes 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

Another Example of Destructor to create log file after completion of program:-
import time
class Addition:
    def __init__(self):
        self.a=100
        self.b=200
    def add(self):
        print(self.a+self.b)
    def __del__(self):
        f=open("log.txt","a+")
        f.write("Additon Result is "+str(self.a+self.b))
        f.write("Progrm created date "+ str(time.asctime(time.localtime(time.time()))))
        f.close()
        obj = Addition()
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)
Example of Operator Overloading :-
class Ope:
    def __init__(self,num):
        self.num= num
    def __add__(self,other):
        self.num=(self.num+other.num)+((self.num+other.num)*(18/100))
        return Ope(self.num)
    def __str__(self):
       return str(self.num)
o = Ope(10000)
p = Ope(20000)
t = o + p
print(t)
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 without modification on the actual class.
to implement function overriding, inheritance is mandatory.
Syntax of Function Overriding in Python:-
class ParentClassName:
    def MethodName(self):
          Statement
class ChildClass(ParentClassName):
        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 virus 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
#Program to Manage Companyname and Manager
class Company:
    def accept(self,name):
        self.name=name
    def display(self):
        print(self.name)
class Manager(Company):
    def accept1(self,eid,ename):
        self.eid=eid
        self.ename=ename
    def display1(self):
        print("Id is ",self.eid, " Name is ",self.ename)
obj = Company()
obj.accept("Kangaroo")
obj.display()
obj1 = Manager()
obj1.accept("Kangaroo")
obj1.accept1(1001,"ABC")
obj1.display()
obj1.display1()
Another Example of Single Inheritance
class Company:
    def accept(self):
        self.cid=1001
        self.companyname="XYZ INC"
    def display(self):
        print("Company id is "+str(self.cid))
        print("Company name is "+str(self.companyname))
class Manager(Company):
    def accept1(self,sal):
        self.sal=sal
    def display1(self):
        print("Salary is "+str(self.sal))
obj = Manager()
obj.accept()
obj.accept1(15000)
obj.display()
obj.display1()
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()
class Company:
    def accept(self,name):
        self.name=name
    def display(self):
        print(self.name)
class Manager(Company):
    def accept1(self,eid,ename):
        self.eid=eid
        self.ename=ename
    def display1(self):
        print("Id is ",self.eid, " Name is ",self.ename)
class Developer(Manager):
    def accept2(self,salary):
        self.salary=salary
       def display2(self):
        print("Salary is ",self.salary)
obj1 = Manager()
obj1.accept("Kangaroo")
obj1.accept1(1001,"ABC")
obj1.display()
obj1.display1()
obj2 = Developer()
obj2.accept("Kangaroo")
obj2.accept1(1002,"MNO")
obj2.accept2(45000)
obj2.display()
obj2.display1()
obj2.display2()
Another Example:-
class Company:
    def accept(self):
        self.cid=1001
        self.companyname="XYZ INC"
    def display(self):
        print("Company id is "+str(self.cid))
        print("Company name is "+str(self.companyname))
class Manager(Company):
    def accept1(self,sal):
        self.sal=sal
    def display1(self):
        print("Salary is "+str(self.sal))
class Employee(Manager):
    def accept2(self,bonus):
        self.bonus=bonus
    def display2(self):
        print("Bonus is "+str(self.bonus))
obj = Employee()
obj.accept()
obj.accept1(15000)
obj.accept2(1200);
obj.display()
obj.display1()
obj.display2()
4.3) Hierarchical  Inheritance:-
 One base class to different child class
class A:
   methods
class B(A):
   methods
class C(A):
    methods
class Company:
    def accept(self,name):
        self.name=name
    def display(self):
        print(self.name)
class Manager(Company):
    def accept1(self,eid,ename):
        self.eid=eid
        self.ename=ename
    def display1(self):
        print("Id is ",self.eid, " Name is ",self.ename)
class Developer(Company):
    def accept2(self,salary):
        self.salary=salary
        def display2(self):
        print("Salary is ",self.salary)
obj1 = Manager()
obj1.accept("Kangaroo")
obj1.accept1(1001,"ABC")
obj1.display()
obj1.display1()
obj2 = Developer()
obj2.accept("Kangaroo")
#obj2.accept1(1002,"MNO")
obj2.accept2(45000)
obj2.display()
#obj2.display1()
obj2.display2()
4.4)  Multiple Inheritance:-
 Two base classes in one child class
class A:
     methods

class B:
    methods

class C(A, B):
    methods

  
Example:-
class Company:
    def fun(self):
        print("Company Info")
    def accept(self,name):
        self.name=name
    def display(self):
        print(self.name)
class Manager:
    def fun(self):
        print("Manager Info")
    def accept1(self,eid,ename):
        self.eid=eid
        self.ename=ename
    def display1(self):
        print("Id is ",self.eid, " Name is ",self.ename)
class Developer(Manager,Company):
    def accept2(self,salary):
        self.salary=salary
    def display2(self):
        print("Salary is ",self.salary)
obj1 = Manager()
#obj1.accept("Kangaroo")
obj1.accept1(1001,"ABC")
#obj1.display()
obj1.display1()
obj2 = Developer()
obj2.fun()
obj2.accept("Kangaroo")
obj2.accept1(1002,"MNO")
obj2.accept2(45000)
obj2.display()
obj2.display1()
obj2.display2()
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()
Real-time Example of Function Overriding:-
class AndroidPhone:
    def screen(self):
        print("screen size")
    def multimedia(self):
        print("multimedia")
    def software(self):
        print("nougat")
    def hardware(self):
        print("hardware")
class AndroidPhoneNew(AndroidPhone):
    def screen(self):
        print("new Screen")
    def software(self):
        print("orio")
obj = AndroidPhoneNew()
obj.screen()
obj.multimedia()
obj.software()
obj.hardware()   
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)
What is an abstract class in python?
It is special class that can not be instantiated and it will be used to declare a set of methods that can be used in another class.
An abstract class is used to create a prototype layer into the real-time application.
Python provides ABC module and abstractrmethod decorator to create abstract class and method.
from abc import ABC,abstractmethod
class Smartphone(ABC):
    @abstractmethod
    def screen(self):
        pass
    @abstractmethod
    def multimedia(self):
        pass
    @abstractmethod
    def software(self):
        pass
    @abstractmethod
    def hardware(self):
        pass
class AndroidPhone(Smartphone):
    def screen(self):
        print("screen size")
    def multimedia(self):
        print("multimedia")
    def software(self):
        print("nougat")
    def hardware(self):
        print("hardware")
class AndroidPhoneNew(AndroidPhone):
    def screen(self):
        print("new Screen")
    def software(self):
        print("orio")
Tags

Post a Comment

184Comments

POST Answer of Questions and ASK to Doubt

  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
  86. class student:
    def Accept(self,rno,sname):
    self.rno=rno
    self.sname=sname
    def Display(self):
    print("Rno is",self.rno,"Name is",self.sname)

    obj=student()
    obj.Accept(101,"rahul")
    obj.Display()

    obj1=student()
    obj1.Accept(102,"shika")
    obj1.Display()

    ReplyDelete
  87. class student:
    def viren(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.viren()


    obj1=student()
    obj1.viren()
    obj1.display()
    obj.display()

    ReplyDelete
  88. class Employee:
    def Accept(self,emid,emailid,name,sname,salary,job,exprience,mobileno):
    self.emid=emid
    self.emailid=emailid
    self.name=name
    self.sname=sname
    self.salary=salary
    self.job=job
    self.exprience=exprience
    self.mobileno=mobileno

    def Display(self):
    print("ID is"+str(self.emid))
    print("Email is"+str(self.emailid))
    print("Name is"+str(self.name))
    print("Sname is"+str(self.sname))
    print("Salary is"+str(self.salary))
    print("job is"+str(self.job))
    print("exprience is"+str(self.exprience))
    print("mobile number is"+str(self.mobileno))

    obj=Employee()
    obj.Accept(101,"viren9@gmail.com","viren","singh",10000,"engineer",2,9098581549)
    obj.Display()
    obj1=Employee()
    obj1.Accept(1002,"kuanl98@gmail.com","kunal","raghuwanshi",12000,"selfmen",1,9858154965)
    obj1.Display()


    ReplyDelete
  89. class student:

    def accept(self,name,sname,rno,branch,year,fees,mobileNo):
    self.name=name
    self.sname=sname
    self.rno=rno
    self.branch=branch
    self.year=year
    self.fees=fees
    self.mobileNo=mobileNo


    def display(self):
    print("Name is= "+str(self.name))
    print("sname is= "+str(self.sname))
    print("rno is= "+str(self.rno))
    print("branch is="+str(self.branch))
    print("year is= "+str(self.year))
    print("fees is= "+str(self.fees))
    print("mobileNo is= "+str(self.mobileNo))

    obj=student()
    obj.accept("shubham","soni",101,"Electrical",2,250000,98581549)
    obj.display()
    obj1=student()
    obj1.accept("madhur","rajput",106,"Mech",4,45000,985845125)
    obj1.display()

    ReplyDelete
  90. 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.display()


    obj2=A()
    obj2.fun(50,60)
    obj2.display()

    ReplyDelete
  91. 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(50000,3,2)

    ReplyDelete
  92. class DynamicFunction:
    def fun(self):

    a=int(input("enter the first number"))
    b=int(input("enter the second number"))
    c=a+b
    print(c)

    obj=DynamicFunction()
    obj.fun()



    obj1=DynamicFunction
    obj1.fun()

    ReplyDelete
  93. 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()

    ReplyDelete
  94. 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 the amount"))
    r=float(input("enter the rate"))
    t=float(input("enter the time"))

    obj.accept(p,r,t)
    obj.logic()
    obj.display()

    ReplyDelete
  95. 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(20,20)
    obj.add()

    del obj

    ReplyDelete
  96. class A:
    def __fun(self):
    print("Private")
    def _fun2(self):
    print("protected")
    def fun3(self):
    self.__fun()
    print("public")

    obj=A()

    obj.fun3()

    ReplyDelete
  97. class student:
    def accept(self):
    self.rno=input("Enter roll no")
    self.sname=input("Enter name")
    def display(self):
    print("ROLL NO IS",self.rno,"Name Is",self.sname)
    obj=student()
    obj.accept()
    obj.display()

    obj1=student()
    obj1.accept()
    obj1.display()

    ReplyDelete
  98. class student:
    def accept(self,rno,sname):
    self.rno=rno
    self.sname=sname
    def display(self):
    print("Rno is",self.rno,"Name is",self.sname)

    obj=student()
    obj.accept(1001,"Gourav")
    obj.display()

    obj1=student()
    obj1.accept(1002,"Hemant")
    obj1.display()

    ReplyDelete
  99. class bank:
    balance=50000
    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)

    ReplyDelete
  100. 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()

    ReplyDelete
  101. 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","hemant","clerk",15000)
    obj.display()
    obj1=employee()
    obj.accept("1005","gourav","account",14000)
    obj.display()

    ReplyDelete
  102. #Program to manage Location, Branch and Institute

    class Location:
    def accept(self,locationname):
    self.locationname=locationname
    def display(self):
    print("location is "+str(self.locationname))

    class Branch(Location):
    def accept1(self,branchname):
    self.branchname=branchname
    def display1(self):
    print("branch name is "+str(self.branchname))


    class Institute(Branch):
    def accept2(self,instname):
    self.instname=instname
    def display2(self):
    print("institute name is "+str(self.instname))



    obj = Institute()
    obj.accept("Palasia")
    obj.accept1("Head")
    obj.accept2("SCS")
    obj.display()
    obj.display1()
    obj.display2()

    ReplyDelete
  103. class Location:
    def accept(self,locationname,plotsize,costofside):
    self.locationname=locationname
    self.plotsize=plotsize
    self.costofside=costofside
    def display(self):
    print("location is " +str(self.locationname),"plot size is " +str(self.plotsize),"Costofside is " +str(self.costofside))

    class Branch(Location):
    def accept1(self,Branchname,address,phonenumber,officetime):
    self.Branchname=Branchname
    self.address=address
    self.phonenumber=phonenumber
    self.officetime=officetime
    def display1(self):
    print("Branchname is " +str(self.Branchname),"address is "+str(self.phonenumber),"officetime is "+str(self.officetime))

    class institute(Branch):
    def accept2(self,insname,coursename,fees):
    self.insname=insname
    self.coursename=coursename
    self.fees=fees
    def display2(self):
    print("insname is " +str(self.insname),"coursename is "+str(self.coursename),"fees is "+str(self.fees))

    obj=institute()
    obj.accept("palasiya",12*30,120000000)
    obj.accept1("GheetaBhawan" ,"industryhouse",5623235965," 10to8 o'clock ")
    obj.accept2("chamelidei","Engineering",5000)
    obj.display()
    obj.display1()
    obj.display2()


    ReplyDelete
  104. #Inheritance Example for Area of the circle, triangle, and rectangle:-
    class Circle:
    def accept(self,param1):
    self.param1=param1
    def areaofcircle(self):
    self.area=3.14*self.param1*self.param1


    def display(self):
    print("Area is "+str(self.area))


    class Tringle(Circle):
    def accept(self,param2):
    self.param2=param2
    def areaoftringle(self):
    self.area=(self.param1*self.param2)/2


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

    print("Area of the circle ")
    obj=Circle()
    obj.accept(12)
    obj.areaofcircle()
    obj.display()

    print("Area of Tringle ")
    obj1=Tringle()
    obj1.accept(12)
    obj1.accept(2)
    obj1.areaoftringle()
    obj1.display()

    print("Area of Rectangle ")

    obj2=Rect()
    obj2.accept(12)
    obj2.accept(2)
    obj2.areaofrectangle()
    obj2.display()



    ReplyDelete
  105. # WAP to manage five student records using rno, marks, and age and display max-age and max marks of students?

    #Snehashish Dutta
    #Batch -11pm - 12pm (python)
    class Student:
    def __init__(self,rno,marks,age):
    self.rno= rno
    self.marks=marks
    self.age=age
    def hmarks(obj1,obj2,obj3,obj4,obj5):
    return max(obj1.marks,obj2.marks,obj3.marks,obj4.marks,obj5.marks)
    def hage(obj1,obj2,obj3,obj4,obj5):
    return max(obj1.age,obj2.age,obj3.age,obj4.age,obj5.age)

    obj1=Student(1,58,24)
    obj2=Student(2,68,25)
    obj3=Student(3,70,26)
    obj4=Student(4,89,27)
    obj5=Student(5,44,21)

    print("The highest marks is=",Student.hmarks(obj1,obj2,obj3,obj4,obj5))
    print("The highest age is=",Student.hage(obj1,obj2,obj3,obj4,obj5))

    ReplyDelete
  106. #Program to manage Doctor, partient, appointment
    #single inheritance
    class Doctor:
    def doctor(self,name,location):
    self.name=name
    self.location=location
    def display(self):
    print("Name of Doctor:"+str(self.name))
    print("Location of clinic:"+str(self.location))

    class Patient(Doctor):
    def personinfo(self,regno,name1,age):
    self.regno=regno
    self.name1=name1
    self.age=age
    def display1(self):
    print("Registration number:"+str(self.regno))
    print("Patient name:"+str(self.name1))
    print("Age of Patient:"+str(self.age))

    class Appointment(Patient):
    def time(self,time):
    self.time=time
    def display2(self):
    print("Appointment time:"+str(self.time))
    obj=Appointment()
    obj.doctor("Dr. Harish Kumawat "," MG Hospital, Dewas-455001 " )
    obj.personinfo(134009," Snehashish Dutta ",24)
    obj.time("11:00 pm")
    obj.display()
    obj.display1()
    obj.display2()

    ReplyDelete
  107. #WAP to Add two list element in single list using class?
    class Addlist:
    def accept(self):
    self.lst=[2,4,3,4,3]
    self.lst1=[2,4,5,6,3]
    def logiclist(self):
    self.lst2=self.lst+self.lst1

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

    obj=Addlist()
    obj.accept()
    obj.logiclist()
    obj.display()

    ReplyDelete
  108. #WAP to display maximum element in list using class ?
    class Maxlst:
    def accept(self):
    self.lst=[2,3,4,5,6]
    def max(self):
    self.m=0
    for i in range(0,len(self.lst)):
    if self.m<self.lst[i]:
    self.m=self.lst[i]
    def display(self):
    print(self.m)
    obj=Maxlst()
    obj.accept()
    obj.max()
    obj.display()

    ReplyDelete
  109. #WAP to display maximum element in list using class ?
    class Maxlst:
    def accept(self):
    self.lst=[2,3,4,5,6]
    def max(self):
    self.m=0
    for i in range(0,len(self.lst)):
    if self.m<self.lst[i]:
    self.m=self.lst[i]
    def display(self):
    print(self.m)
    obj=Maxlst()
    obj.accept()
    obj.max()
    obj.display()

    ReplyDelete
  110. #WAP to display fibonacci series using class ?
    class Fibonacci:
    def accept(self):
    self.num=int(input("Enter Any number"))
    def fiblogic(self):
    self.a=-1
    self.b=1
    for i in range(0,self.num+1):
    self.c=self.a+self.b
    print(self.c)
    self.a=self.b
    self.b=self.c


    obj=Fibonacci()
    obj.accept()
    obj.fiblogic()




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

    def logic(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,"is Not Prime")
    else:
    print(self.n," is Prime number")


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

    def logic(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,"is Not Prime")
    else:
    print(self.n," is Prime number")


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

    ReplyDelete
  112. class Maximum:
    def accept(self):
    self.lst=[2,3,4,5,6]
    def logic(self):
    self.a=0
    for i in range(0,len(self.lst)):
    if self.a<self.lst[i]:
    self.a=self.lst[i]
    def display(self):
    print("The maximum element is:",self.a)
    obj=Maximum()
    obj.accept()
    obj.logic()
    obj.display()

    ReplyDelete
  113. Pattern based Program using OOPS:-

    class Star:
    def accept(self,row):
    self.row = row

    def logic(self):
    self.res=""
    for i in range(1,self.row+1):

    for j in range(1,i+1):
    self.res = self.res + str(i) + " "
    self.res += "\n"
    def display(self):
    print(self.res)

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



    ReplyDelete
  114. Program to Reverse List using OOPS:-
    class ListReverse:
    def accept(self,x):
    self.x = x

    def logic(self):
    self.lst=[]
    for i in range(len(self.x)-1,-1,-1):
    self.lst.append(self.x[i])

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

    obj = ListReverse()
    obj.accept([1,2,3,4,5])
    obj.logic()
    obj.display()



    ReplyDelete
  115. #star program using oops
    class star:
    def accept(self,row):
    self.row=row
    def logic(self):
    self.res=""
    for i in range(1,self.row+1):
    for j in range(1,i+1):
    self.res=self.res+str(i)+" "
    self.res+="\n"
    def display(self):
    print(self.res)
    obj=star()
    obj.accept(6)
    obj.logic()
    obj.display()

    ReplyDelete
  116. #prime number using class

    class prime:
    def accept(self,num):
    self.num=num
    def logic(self):
    self.res=""
    for i in range(2,self.num):
    if self.num%i==0:
    self.res="no prime"
    break
    else:
    self.res="prime"

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




    obj=prime()
    obj.accept(9)
    obj.logic()
    obj.display()

    ReplyDelete
  117. #WAP to print star pattern using class with parameter in oops?
    class Star:
    def accept(self,row):
    self.row=row
    def logic(self):
    self.res=""
    for i in range(1,self.row+1):
    for j in range(1,i+1):
    self.res=self.res+str("*")+" "
    self.res+="\n"
    def display(self):
    print(self.res)
    obj = Star()
    obj.accept(5)
    obj.logic()
    obj.display()

    ReplyDelete
  118. class fact:
    def accept(self):
    self.num=int(input("enter num1"))


    def fact(self):
    self.f=1
    for i in range(1,self.num+1):
    self.f=self.f*i

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

    obj=fact()
    obj.accept()
    obj.fact()
    obj.display()

    ReplyDelete
  119. #Program to Display EmpInfo using Static and Dynamic

    class Employee:
    def Accept(companyname):
    Employee.companyname=companyname
    def AcceptEmp(self,empid,name,job,salary):
    self.empid=empid
    self.name=name
    self.job=job
    self.salary=salary
    def Display():
    print("Company name is ",Employee.companyname)

    def DisplayEmp(self):
    print("Empid is",self.empid,"Name is ",self.name, "Job is ", self.job , "Salary is ", self.salary)


    Employee.Accept("SCS")
    Employee.Display()
    emp1 = Employee()
    emp1.AcceptEmp(1001,"XYZ","Manager",12000)
    emp1.DisplayEmp()



    ReplyDelete
  120. # wap revers the list using accept,logic,display.
    class revlist:
    def accept(self,x):
    self.x=x
    def logic(self):
    self.list=[]
    for i in range(len(self.x)-1,-1,-1):
    self.list.append(self.x[i])
    def display(self):
    print(self.list)




    obj=revlist()
    obj.accept([1,2,3,4,5])
    obj.logic()
    obj.display()

    ReplyDelete
  121. #wap si of constructor.

    class si:
    def __init__(self,p,r,t):
    self.p=p
    self.t=t
    self.r=r
    def logic(self):
    self.si=(self.p*self.t*self.r)/100
    def display(self):
    print(self.si)


    obj=si(15000,8,6)
    obj.logic()
    obj.display()

    ReplyDelete
  122. #wap to simple interest using 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(self.si)

    obj = SI(1000,5.2,2)
    obj.logic()
    obj.display()

    ReplyDelete
  123. #wap to simple interest using 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)

    obj = SI(2000,4.6,3)
    obj.logic()
    obj.display()

    ReplyDelete
  124. #wap to used constructor in simple interest
    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)
    obj=si(2500,5.2,5)
    obj.logic()
    obj.display()

    ReplyDelete
  125. #Example of a employe object that represents the characteristics of employe using empid and empname , salary that has been defined as to accept() and display().


    class employe:
    def Accept(self,empid,empname, salary):
    self.empid=empid
    self.empname=empname
    Self.salary=salary
    def Display(self):
    print("empid is ",self.empid," empname is ",self.empname,"salary is",self.salary)


    emp =employe()
    emp.Accept(1001,"vihi",10000)
    emp.Display()


    emp1 = employe()
    emp1.Accept(1002,"viru",12000)
    emp1.Display()

    ReplyDelete
  126. #WAP make a class static and instance type in oops?

    class Student:
    def accept(clgname):
    Student.clgname="AITR"

    print(Student.clgname)
    def accept1(self,stdid,stdname,stdcourse):
    self.stdid=stdid
    self.stdname=stdname
    self.stdcourse=stdcourse



    def display(self):
    print("Student id " +str(self.stdid), "Student name "+str(self.stdname), "Student course "+str(self.stdcourse))
    obj=Student()
    obj.accept()
    obj.accept1(101,"Anku","MCA")
    obj.display()


    ReplyDelete
  127. class CAR:
    def accept(Ccompany):
    CAR.Ccompany="TATA"
    print(CAR.Ccompany)
    def accept1(self):
    self.Cname=(input("Enter CAR Name "))
    self.Ccolor=input("Enter CAR Colors ")
    self.Cmodel=int(input("Enter CAR model "))
    def display(self):
    print("CAR Name Is== "+str(self.Cname), "CAR Colors is== "+str(self.Ccolor),"CAR model is== "+str(self.Cmodel))

    obj = CAR()
    obj.accept()
    obj.accept1()
    obj.display()

    ReplyDelete
  128. #program of student using static and dynamic?
    class student:
    def accept(schoolname):
    student.schoolname=schoolname
    def acceptstu(self,name,rno,standard):
    self.name=name
    self.rno=rno
    self.standard=standard
    def display():
    print("school name is",student.schoolname)

    def displaystu(self):
    print("name is",self.name," rno is",self.rno," standard is",self.standard)

    student.accept("sanskar vally")
    student.display()

    obj=student()
    obj.acceptstu('xyz','1001','10th')
    obj.displaystu()

    ReplyDelete
  129. class Triangle:
    def accept(self,base,heigth):
    self.base=base
    self.heigth=heigth


    def logic(self):
    self.area=(self.base*self.heigth)/2

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


    obj = Triangle()
    obj.accept(100,2)
    obj.logic()
    obj.display()

    ReplyDelete
  130. #WAP area of Rectangle using constructor in oops?

    class Reatangle:
    def __init__(self,length,width):
    self.length=length
    self.width=width

    def logic(self):
    self.area=(self.length*self.width)

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

    obj = Reatangle(20,10)
    obj.logic()
    obj.display()

    ReplyDelete
  131. #simple interest using 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("SI is",self.si)

    p=float(input("enter p"))
    r=float(input("enter r"))
    t=float(input("enter t"))

    obj=si(p,r,t)
    obj.logic()
    obj.display()

    ReplyDelete
  132. class student:
    def accept(self):
    self.rno=input("Enter rno")
    self.sname=input("Enter name")
    self.branch=input("Enter branch")
    Self.fees=input("Enter fees")
    Self.department =input("Enter department")
    def display(self):
    print("rno is ",self.rno,"name is",self.sname ," branch is", self.branch,"fees is",self.fees,"department is",self.department )
    for i in range(0,5 )
    obj=student()
    obj.accept()
    obj.display()

    ReplyDelete
  133. #Program for prime number?
    class Prime:
    def accept(self):
    self.num = int (input ("Enter number"))


    def logic(self):
    self.result=""
    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()
    obj.logic()
    obj.display()

    ReplyDelete
  134. WAP to calculate the factorial, and Fibonacci series program and three methods (accept, logic, display)

    #solution factoriyal
    class Fact:
    def accept(self):
    self.num = int (input ("enter number"))
    def logic(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()
    obj.logic()
    obj.display()

    #solution fibbonscci series:-
    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(5)
    obj.logic()
    obj.display()

    ReplyDelete
  135. #WAP to check given number is prime or not using Destructor in oops?
    class Prime:
    def __init__(self,num):
    self.num=num
    def logic(self):
    for i in range(2,self.num):
    if self.num%i==0:
    print("not Prime")
    break
    else:
    print("Prime")
    def __del__(self):
    print("Destructor will called")
    obj = Prime(4)
    obj.logic()
    del obj

    ReplyDelete
  136. #Nishika Gour
    #WAP to calculate the factorial, and Fibonacci series program and three methods (accept, logic, display)

    #solution factoriyal
    class Fact:
    def accept(self):
    self.num = int (input ("enter number"))
    def logic(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()
    obj.logic()
    obj.display()

    #solution fibbonscci series:-
    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(5)
    obj.logic()
    obj.display()

    ReplyDelete
  137. #Nsihika Gour
    # wap to display students information
    class student:
    def accept(self):
    self.rno=input("Enter rno")
    self.sname=input("Enter name")
    self.branch=input("Enter branch")
    Self.fees=input("Enter fees")
    Self.department =input("Enter department")
    def display(self):
    print("rno is ",self.rno,"name is",self.sname ," branch is", self.branch,"fees is",self.fees,"department is",self.department )
    for i in range(0,5 )
    obj=student()
    obj.accept()
    obj.display()

    ReplyDelete
  138. #Nsihika Gour
    #Program for prime number?
    class Prime:
    def accept(self):
    self.num = int (input ("Enter number"))


    def logic(self):
    self.result=""
    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()
    obj.logic()
    obj.display()

    ReplyDelete
  139. # Nishika Gour
    # solution of simple interest
    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 the amount"))
    r=float(input("enter the rate"))
    t=float(input("enter the time"))

    obj.accept(p,r,t)
    obj.logic()
    obj.display()

    ReplyDelete
  140. #wap to simple interest using 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(self.si)

    obj = SI(1000,5.2,2)
    obj.logic()
    obj.display()

    ReplyDelete
  141. 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()

    ReplyDelete
  142. #wap to calculate simple interest using static data member only
    class SI:
    p,r,t=1000,2,3 #class type
    res=(SI.p*SI.r*SI.t)/100
    print(res)

    ReplyDelete
  143. #Example of class ?
    class hospital :
    def accept(self,empname,empid,hosaddress,hosname):
    self.empname=empname
    self.empid=empid
    self.hosaddress=hosaddress
    self.hosname=hosname
    def display(self):
    print("empname is",self.empname,"empid is",self.empid,"hosaddress is",self.hosaddress,"hosname is",self.hosname)

    obj=hospital()
    obj.accept( "neha",101,"khandwa road indore","chl hospital")
    obj.display()

    ReplyDelete
  144. # example of instance variable
    class Hotal:
    def fun(self,hotalname,ownername,hotaladdress):
    self.hotalname=hotalname
    self.ownername=ownername # instance type or dynamic
    self.hotaladdress=hotaladdress
    def display(self):
    print("hotalname is",self.hotalname,"ownername is", self.ownername ,"hotaladdress" ,self.hotaladdress)
    obj=Hotal()
    obj.fun("ranjit singh","mr.ranjit singh","near by s.n.college khandwa")
    obj.display()

    ReplyDelete
  145. #STATIC EXAMPLE
    class Staticfun:
    collegename="sdits khandhwa"
    def fun():
    for i in range(0,5):
    a=int(input("enter number"))
    b=int(input("enter number"))
    c=a+b
    print(c)
    for i in range(0,5):
    print(Staticfun.collegename)
    Staticfun.fun()

    ReplyDelete
  146. #STATIC EXAMPLE
    class Staticfun:
    collegename="sdits khandhwa"
    def fun():
    for i in range(0,5):
    a=int(input("enter number"))
    b=int(input("enter number"))
    c=a+b
    print(c)
    for i in range(0,4):
    print(Staticfun.collegename)
    Staticfun.fun()

    ReplyDelete
  147. #wap to calculate simple interest using static data member only
    class SI:
    p,r,t=3000,5,3 #class type
    res=(SI.p*SI.r*SI.t)/100
    print(res)

    ReplyDelete
  148. # example of instance variable
    class Hotal:
    def fun(self,hotalname,ownername,hotaladdress):
    self.hotalname=hotalname
    self.ownername=ownername # instance type or dynamic
    self.hotaladdress=hotaladdress
    def display(self):
    print("hotalname is",self.hotalname,"ownername is", self.ownername ,"hotaladdress" ,self.hotaladdress)
    obj=Hotal()
    obj.fun("ranjit singh","mr.ranjit singh","near by s.n.college khandwa")
    obj.display()
    obj1.fun("kesar",mr.sonu singh,"Ramnagar Khandwa")
    obj1.display()

    ReplyDelete
  149. #example of intance type or dynamic?

    class bank:
    def accept(self,accountno,name,branch,bankname):
    self.accountno=accountno
    self.name=name
    self.branch=branch
    self.bankname=bankname
    def display(self):
    print("accountno is",self.accountno,"name is"+str(self.name)+"branch is"+str(self.branch)+"bankname is"+str(self.bankname))

    obj=bank()
    obj.accept(345678923023,"vini","xyz","sbi")
    obj.display()
    obj1=bank()
    obj1.accept(6789564534222,"mahi","abc","hdfc")
    obj1.display()

    ReplyDelete
  150. #Program to Display EmpInfo using Static and Dynamic

    class Employee:
    def Accept(companyname):
    Employee.companyname=companyname
    def AcceptEmp(self,empid,name,job,salary):
    self.empid=empid
    self.name=name
    self.job=job
    self.salary=salary
    def Display():
    print("Company name is ",Employee.companyname)

    def DisplayEmp(self):
    print("Empid is",self.empid,"Name is ",self.name, "Job is ", self.job , "Salary is ", self.salary)


    Employee.Accept("tcs")
    Employee.Display()
    emp1 = Employee()
    emp1.AcceptEmp(1001,"abc","Manager",10000)
    emp1.DisplayEmp()

    ReplyDelete
  151. #calculate si only using constructor
    #NAME-anjali verma

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


    obj=SI(10000,5,2)

    ReplyDelete
  152. class DynamicFunction:
    def fun(self):

    a=int(input("enter the first number"))
    b=int(input("enter the second number"))
    c=a+b
    d=a*b
    print(c)
    Print (d)

    obj=DynamicFunction()
    obj.fun()



    obj1=DynamicFunction
    obj1.fun()

    ReplyDelete
  153. #wap to mult. two number using operater overloading ?
    class Oo:
    def __init__(self,num):
    self.num=num
    def __add__(self,other):
    return Oo(self.num*other.num)

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

    Ankit = Oo(100)
    Ankit1 = Oo(20)
    Ankit2 = Ankit+Ankit1
    print(Ankit2)

    ReplyDelete
  154. # another example ?
    class Oo1:
    def __init__(self,num):
    self.num=num

    def __sub__(self,other):
    return Oo1(self.num+other.num)
    def __str__(self):
    return str(self.num)

    Ankit = Oo1(100)
    Ankit1 = Oo1(20)
    Ankit2 = Ankit-Ankit1
    print(Ankit2)

    ReplyDelete
  155. # Another Example Operater Overloading?
    class Oo2:
    def __init__(self,a):
    self.a = a
    def __mul__(self,b):
    return Oo2(self.a+b.a)
    def __str__(self):
    return str(self.a)

    Ankit = Oo2(10)
    Ankit1 = Oo2(2)
    Ankit2 = Ankit*Ankit1
    print(Ankit2)

    ReplyDelete
  156. # Another 3rd Example of operater overloading ?
    class Oo3:
    def __init__(self,a):
    self.a = a
    def __truediv__(self,b):
    return Oo3(self.a/b.a)
    def __str__(self):
    return str(self.a)

    Ankit = Oo3(20)
    Ankit1 = Oo3(2)
    Ankit2 = Ankit/Ankit1
    print(Ankit2)

    ReplyDelete
  157. # Another 4th Example of operater overloading
    class Oo4:
    def __init__(self,x):
    self.x = x
    def __floordiv__(self,y):
    return Oo4(self.x % y.x)
    def __str__(self):
    return str(self.x)

    Ankit = Oo4(int(input("Enter The Number")))
    Ankit1 = Oo4(int(input("Enter The Number")))
    Ankit2 = Ankit//Ankit1
    print(Ankit2)

    ReplyDelete
  158. # wap represent the characteristic of student:
    #Anjali verma

    class student:
    def accept(self):
    self.rno=input("enter rno")
    self.name=input("enter name")
    def display(self):
    print("rno is",self.rno,"name is",self.name)


    obj=student()
    obj.accept()
    obj.display()

    ReplyDelete
  159. 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(13)
    num2=Overloading(2)


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

    ReplyDelete
  160. #wap operator overloading using +operator
    #anjali verma
    class ope:
    def __init__(self,num):
    self.num=num
    def __add__(self,other):
    return ope(self.num*other.num)
    def __str__(self):
    return str(self.num)


    obj=ope(10)
    obj1=ope(5)
    obj3=obj+obj1
    print("It is add operator=",obj3)


    #wap operator overloading using -operator
    class ope:
    def __init__(self,num):
    self.num=num
    def __sub__(self,other):
    return ope(self.num*other.num)
    def __str__(self):
    return str(self.num)


    obj=ope(100)
    obj1=ope(52)
    obj3=obj-obj1
    print("It is sub operator=",obj3)

    ReplyDelete
  161. # WAP to multilevel Inheritance example?
    class Company:
    def accept(self,name):
    self.name = name
    def display(self):
    print(self.name)

    class manager(Company):
    def accept1(self,mid,mname):
    self.mid = mid
    self.mname = mname

    def display1(self):
    print(self.mid,self.mname)
    class staff(manager):
    def accept2(self,sal):
    self.sal = sal
    def display2(self):
    print(self.sal)

    obj = staff()
    obj.accept("SCS")
    obj.accept1(111,"Thakur")
    obj.accept2(20000)
    obj.display()
    obj.display1()
    obj.display2()

    ReplyDelete
  162. #WaP to single inheritance ?
    class State:
    def accept(self,sname):
    self.sname = sname

    def display(self):
    print(self.sname)
    class Dist(State):
    def accept1(self,dname):
    self.dname = dname
    def display1(self):
    print(self.dname)

    obj = Dist()
    obj.accept("Madhya Pradesh")
    obj.accept1("Satna")
    obj.display()
    obj.display1()

    ReplyDelete
  163. #wap convert doller to rs and rs to doller.
    #anjali verma
    class option:
    def __init__(self,num):
    self.num=num
    def __add__(self,other):
    return option((self.num+self.num)*75)
    def __mul__(self,other):
    return option((self.num+self.num)/75)
    def __str__(self):
    return str(self.num)

    obj=option(10)
    obj1=option(20)
    obj2=obj+obj1
    obj3=obj*obj1
    print("$ is",obj2)
    print("Rs is",obj3)

    ReplyDelete
  164. #hierarchical inheritance?
    class Company:
    def accept(self,name):
    self.name=name
    def display(self):
    print(self.name)

    class Manager(Company):
    def accept1(self,eid,ename):
    self.eid=eid
    self.ename=ename
    def display1(self):
    print("Id is ",self.eid, " Name is ",self.ename)

    class Developer(Company):
    def accept2(self,salary):
    self.salary=salary

    def display2(self):
    print("Salary is ",self.salary)
    obj=Company()
    obj.accept("kangaroo")
    obj.display()

    obj1 = Manager()
    obj1.accept("Kangaroo")
    obj1.accept1(1001,"ABC")
    obj1.display()
    obj1.display1()

    obj2 = Developer()
    obj2.accept("Kangaroo")
    obj2.accept2(45000)
    obj2.display()
    obj2.display2()

    ReplyDelete
  165. # Multilevel inheritence
    # Anjali Verma

    class school:
    def accept(self,schlname):
    self.schlname=schlname
    def display(self):
    print(self.schlname)
    class princple(school):
    def accept1(self,rolno,name):
    self.rolno=rolno
    self.name=name
    def display1(self):
    print("Roll no.is",self.rolno)
    print("Student name is",self.name)
    class vice(princple):
    def accept2(self,fees):
    self.fees=fees
    def display2(self):
    print("Fees is",self.fees)


    obj1=princple()
    obj1.accept("Jhonson English Medium")
    obj1.accept1(1001,"Anjali Verma")
    obj1.display()
    obj1.display1()


    obj2=vice()
    obj2.accept1(1025,"Haritesh Verma")
    obj2.accept2(45000)
    obj2.display1()
    obj2.display2()

    ReplyDelete
  166. #multipal inheritance?
    class Company:
    def accept(self,name):
    self.name=name
    def display(self):
    print(self.name)

    class Manager():
    def accept1(self,eid,ename):
    self.eid=eid
    self.ename=ename
    def display1(self):
    print("Id is ",self.eid, " Name is ",self.ename)

    class Developer(Company,Manager):
    def accept2(self,salary):
    self.salary=salary

    def display2(self):
    print("Salary is ",self.salary)
    obj=Company()
    obj.accept("kangaroo")
    obj.display()

    obj1 = Manager()
    obj1.accept1(1001,"ABC")
    obj1.display1()

    obj2 = Developer()
    obj2.accept("Kangaroo")
    obj2.accept1(1002,"xyz")
    obj2.accept2(45000)
    obj2.display()
    obj2. display1()
    obj2.display2()

    ReplyDelete
  167. #Single inheritance

    class Company:
    def accept(self,name):
    self.name=name
    def display(self):
    print("Company name:",self.name)

    class Manager(Company):
    def accept1(self,name):
    self.name = name
    def display1(self):
    print("Employee name:",self.name)

    obj=Company()

    obj1=Manager()
    obj1.accept("Infosys")
    obj1.display()
    obj1.accept1("XYZ")
    obj1.display1()

    ReplyDelete
  168. #Multilevel inheritance

    class Company:
    def accept(self,name):
    self.name=name
    def display(self):
    print("Company name:",self.name)

    class Manager(Company):
    def accept1(self,name):
    self.name = name
    def display1(self):
    print("Employee name:",self.name)

    class Developer(Manager):
    def accept2(self, empid, salary):
    self.empid = empid
    self.salary=salary
    def display2(self):
    print("The employee id is:",self.empid, "Salary is:",self.salary)

    obj=Company()

    obj1=Manager()
    obj2=Developer()
    obj2.accept("Infosys")
    obj2.display()
    obj2.accept1("ABS")
    obj2.display1()
    obj2.accept2(1002,24000)
    obj2.display2()

    ReplyDelete
  169. #Multiple inheritance

    class Company:
    def accept(self,name):
    self.name=name
    def display(self):
    print("Company name:",self.name)

    class Designation:
    def accept1(self,des, empid, salary):
    self.des = des
    self.empid = empid
    self.salary=salary
    def display1(self):
    print("Designation:",self.des)
    print("Employee ID:",self.empid)
    print("Salary:",self.salary)

    class Employee(Company,Designation):
    pass

    obj=Company()

    obj1=Designation()

    obj2=Employee()
    obj2.accept("Pablo softwares")
    obj2.display()
    obj2.accept1("Senior Developer", 1001, 30000)
    obj2.display1()

    ReplyDelete
  170. #Hierarichal inheritance

    class Company:
    def accept(self,name,post,empid, salary):
    self.name=name
    self.post=post
    self.empid=empid
    self.salary=salary
    def display(self):
    print("Company name:",self.name)
    print("Desigation:",self.post)
    print("employee ID:",self.empid)
    print("Salary:",self.salary)

    class Employee1(Company):
    def accept1(self, name):
    self.name=name
    def display1(self):
    print("Name:",self.name)

    class Employee2(Company):
    def accept2(self,name):
    self.name=name
    def display2(self):
    print("Name:",self.name)

    obj=Company()

    obj1=Employee1()
    obj1.accept1("ABC")
    obj1.display1()
    obj1.accept("Delloite","Manager",1010, 50000)
    obj1.display()

    obj2=Employee2()
    obj2.accept2("XYZ")
    obj2.display2()
    obj2.accept("Kangaroo Softwares","Developer",1002,20000)
    obj2.display()



    ReplyDelete
  171. #Hierarchica inheritance

    class Bank:
    def Bankinfo(self,name,location):
    self.name=name
    self.location=location
    def display(self):
    print("Bank Name",self.name,"Location",self.location)
    class Branch(Bank):
    def Branchinfo(self,Bname,Bcode):
    self.Bname=Bname
    self.Bcode=Bcode
    def display1(self):
    print("Branch Name",self.Bname,"Branch code",self.Bcode)
    class OtherBranch(Bank):
    def locatinfo(self,address):
    self.address=address
    def display2(self):
    print("adress is ",self.address)

    print("Bank info")
    obj=Bank()
    obj.Bankinfo("SBI","Vijay Nagar Indore")
    obj.display()

    print("Branch info")
    obj1=Branch()
    obj1.Bankinfo("SBI","In front Of Bombay hospital")
    obj1.Branchinfo("Bombay hospital",452011)
    obj1.display()
    obj1.display1()

    print("Other Branch info")
    obj2=OtherBranch()
    obj2.Bankinfo("SBI","IN front of Radisson Blu Hotel")
    obj2.locatinfo("Near C21 Business Park")
    obj2.display()
    obj2.display2()

    ReplyDelete
  172. # multiple inheritence

    class university:
    def uname(self,name):
    self.name=name
    def display1(self):
    print(self.name)
    class college(university):
    def collegename(self,cname,collegeid):
    self.cname=cname
    self.collegeid=collegeid
    def display2(self):
    print(self.cname,self.collegeid)
    class principle(college):
    def principlename(self,pname):
    self.pname=pname
    def display3(self):
    print(self.pname)
    class teacher(principle):
    def teachername(self,tname,salary):
    self.tname=tname
    self.salary=salary
    def display4(self):
    print(self.tname,self.salary)
    class student(teacher):
    def students(self,sname,rollno,branch):
    self.sname=sname
    self.rollno=rollno
    self.branch=branch
    def display5(self):
    print(self.sname,self.rollno,self.branch)
    print("university name is:-")
    obj=university()
    obj.uname("RGPV")
    obj.display1()
    print("college name is:-")
    obj1=college()
    obj1.uname("RGPV")
    obj1.display1()
    obj1.collegename("government ujjain engineering college",123)
    obj1.display2()
    print("principle name:-")
    obj2=principle()
    obj2.collegename("government ujjain engineering college",123)
    obj2.display2()
    obj2.principlename("xyz")
    obj2.display3()
    print("teacher details is:-")
    obj3=teacher()
    obj3.teachername("aaa sir","2000/-rs")
    obj3.display4()
    print("student details is:-")
    obj4=student()
    obj4.students("arav",123,"computer science")
    obj4.display5()







    ReplyDelete
  173. #Multilevel inheritance
    class company:
    def accept(self,name):
    self.name=name
    def display(self):
    print(self.name)

    class manager(company):
    def accept1(self,eid,ename):
    self.eid=eid
    self.ename=ename
    def display1(self):
    print("id is",self.eid,"name is",self.ename)

    class developer(manager):
    def accept2(self,salary):
    self.salary=salary
    def display2(self):
    print("salary is",self.salary)

    obj1=manager()
    obj1.accept("wipro")
    obj1.accept1(1001,'xyz')
    obj1.display()
    obj1.display1()

    obj2=developer()
    obj2.accept("wipro")
    obj2.accept1(1002,'yash')
    obj2.accept2(20000)
    obj2.display()
    obj2.display1()
    obj2.display2()


    ReplyDelete
  174. #multiple Inheritance?
    class Principal:
    def accept(self,name):
    self.name = name
    def display(self):
    print(self.name)

    class HOD(Principal):
    def accept1(self,Hname,Branch):
    self.Hname = Hname
    self.Branch = Branch
    def display1(self):
    print(self.Hname,self.Branch)

    class Tutor(HOD,Principal):
    def accept2(self,Tname,Subject):
    self.Tname = Tname
    self.Subject = Subject
    def display2(self):
    print(self.Tname,self.Subject)

    Ak = Tutor()
    Ak.accept("Shubh")
    Ak.display()
    Ak.accept1("ram","IT")
    Ak.display1()
    Ak.accept2("Ram","C++")

    Ak.display2()
    #multiple Inheritance?
    class Principal:
    def accept(self,name):
    self.name = name
    def display(self):
    print(self.name)

    class HOD(Principal):
    def accept1(self,Hname,Branch):
    self.Hname = Hname
    self.Branch = Branch
    def display1(self):
    print(self.Hname,self.Branch)

    class Tutor(HOD,Principal):
    def accept2(self,Tname,Subject):
    self.Tname = Tname
    self.Subject = Subject
    def display2(self):
    print(self.Tname,self.Subject)

    Ak = Tutor()
    Ak.accept("Shubh")
    Ak.display()
    Ak.accept1("Prasad","IT")
    Ak.display1()
    Ak.accept2("Ram","C++")

    Ak.display2()

    ReplyDelete
  175. #Example of Class and Object ?

    class rgpv:
    def method(self,studentname,studentid,branch,fees):
    self.studentname = studentname
    self.studentid = studentid
    self.branch = branch
    self.fees = fees
    def display(self):
    print("student name is","=",self.studentname)
    print("student id is","=",self.studentid)
    print("branch name","=",self.branch)
    print("fees","=",self.fees)

    obj = rgpv()
    obj.method("abhi",1001,"mechanical",26000)
    obj.display()

    ReplyDelete
  176. #Example of Class and Object ?

    class employee:
    def object(self,empname,empid,empdesig,empsalary):
    self.empname = empname
    self.empid = empid
    self.empdesig = empdesig
    self.empsalary = empsalary
    def display(self):
    print("employee name","=",""+str(self.empname))
    print("employee id","=",""+str(self.empid))
    print("employee designation","=",""+str(self.empdesig))
    print("employee salary ","=",""+str(self.empsalary))
    obj=employee()
    obj.object("abhi",1001,"'python developer'",20000)
    obj.display()
    print()
    obj1=employee()
    obj1.object("raj",1002,"'python developer'",20000)
    obj1.display()
    print()
    obj2=employee()
    obj2.object("shiv",2003,"'java developer'",22000)
    obj2.display()

    ReplyDelete
  177. # Single Inheritence :-

    class company:
    def accept(self,name):
    self.name=name
    def display(self):
    print(self.name)

    class manager(company):
    def accept1(self,empid,empname):
    self.empid=empid
    self.empname=empname
    def display1(self):
    print("employee id is ", self.empid , "employee name is ", self.empname )
    obj=company()
    obj.accept("wipro")
    obj.display()

    obj1=manager()
    obj1.accept("wipro")
    obj1.accept1(1001,"yash")
    obj1.display()
    obj1.display1()

    ReplyDelete
  178. #operator overloading for addittion program
    class ope:
    def __init__(self,num):
    self.num=num
    def __add__(self,other):
    return ope((self.num+other.num)+(self.num+other.num))
    def __str__(self):
    return "result" + str(self.num)
    scs=ope(2000)
    scs1=ope(8000)
    sc2=scs+scs1
    print(sc2)

    ReplyDelete
  179. # Hierarchical inheritance
    # Anjali verma

    class player:
    def accept(self,pname):
    self.pname=pname
    def display(self):
    print("Player name is",self.pname)
    class T20(player):
    def accept1(self,run,nout):
    self.run=run
    self.nout=nout
    def display1(self):
    print("Total run is",self.run)
    print("Total not out is",self.nout)
    class Odi(player):
    def accept2(self,noplayer):
    self.noplayer=noplayer
    def display2(self):
    print("Total number of player is",self.noplayer)

    print("PLAYER INFORMATION")
    obj=player()
    obj.accept("= VIRAT")
    obj.display()

    obj1=T20()
    obj1.accept1("= 256","= 5")
    obj1.display1()

    obj2=Odi()
    obj2.accept2("= 11")
    obj2.display2()



    ReplyDelete
  180. # Multiple inheritance
    # Anjali verma

    class Batsman:
    def accept(self,sr,tr,hs,br):
    self.strike_runs=sr
    self.total_runs=tr
    self.highest_score=hs
    self.batting_rank=br
    def display(self):
    print("Strike Rate is",self.strike_runs)
    print("Total Runs is",self.total_runs)
    print("Hightest Score is",self.highest_score)
    print("Batting Rank is",self.batting_rank)
    class Bowlar:
    def accept1(self,wt,ec,ht,bor):
    self.wickets_taken = wt
    self.economy = ec
    self.hattricks = ht
    self.bowling_rank = bor
    def display1(self):
    print("Wickets Taken is:",self.wickets_taken)
    print("Economy is:",self.economy)
    print("Hattricks:", self.hattricks)
    print("Bowling Rank is:",self.bowling_rank)
    class AllRounder( Batsman,Bowlar):
    def accept2(self,ar):
    self.allrounder_rank=ar
    def display2(self):
    print("All Rounder Rank is",self.allrounder_rank)

    print("--BATTING DATA--")
    obj=Batsman()
    obj.accept(89.7,356,96,67)
    obj.display()

    print("--BOWLING DATA--")
    obj1=Bowlar()
    obj1.accept1(101,5.67,4,67)
    obj1.display1()

    print("--ALL ROUNDER DATA--")

    obj2=AllRounder()
    obj2.accept2(57)
    obj2.display2()



    ReplyDelete
  181. # Single inheritance
    # Anjali verma

    class Doctor:
    def accept(self,specialist):
    self.specialist=specialist
    def display(self):
    print("Doctor Specialist :",self.specialist)
    class Appointment:
    def accept1(self,time):
    self.time = time

    def display1(self):
    print("Time of the patient:",self.time)

    class Patient:
    def accept2(self,pid,pname,age,gender):
    self.pid=pid
    self.pname=pname
    self.age=age
    self.gender=gender
    def display2(self):
    print("Patient ID is :",self.pid)
    print("Patient Name is :",self.pname)
    print("patient age is :",self.age)
    print("patient gender is :",self.gender)


    obj=Doctor()
    obj.accept("neurosurgeon")
    obj.display()

    obj1=Appointment()
    obj1.accept1("1pm")
    obj1.display1()

    obj2=Patient()
    obj2.accept2(262,"kajal",24,"Female")
    obj2.display2()



    ReplyDelete
  182. ##1) Manage Patient, Doctor, and Appointment using all possible Inheritance?


    class hospital:
    def accept(self,patient,doctor , appointment):
    self.patient = patient
    self.doctor = doctor
    self.appointment=appointment
    def display(self):
    print('patient name'+ self.patient ,"doctor"+self.doctor, "appointment"+self.appointment , end='')
    obj=hospital()
    obj.accept("manish","dr.gannu","12:30 pm")
    obj.display()

    ReplyDelete
  183. class Add:
    def accept (self,a,b):
    self.a=a
    self.b=b
    self.c=self.a+self.b
    class Dollar(Add):
    def rstodollar(self):
    self.d=obj.c*75
    print("dollar =",self.d)

    obj=Add()
    obj.accept(10,10)
    obj1=Dollar()
    obj1.rstodollar()

    ReplyDelete
Post a Comment