Professional Documents
Culture Documents
10
NAME: SHASHWAT WANKHEDE
ROLL NO: 58
SECTION: A
DATE OF PERFORMANCE: 22/12/21
AIM: Define appropriate classes for any one of the following with
standard methods:
i) Polynomial class
iii)Stack class
Classes.
THEORY:
CODE:
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
#Use the Person class to create an object, and then execute the printname
method:
x = Person("John", "Doe")
x.printname()
#########
class Student(Person):
pass
x = Student("Mike", "Olsen")
x.printname()
# importing package
import numpy
class Polynomial:
def __init__(self):
self.px1 = (5,-2,5)
self.px2 = (2,-5,2)
def addition(self):
rx = numpy.polynomial.polynomial.polyadd(self.px1,self.px2)
print(rx)
def addition1(self,px1,px2):
rx = numpy.polynomial.polynomial.polyadd(px1,px2)
print(rx)
P=Polynomial()
px3=(1,2,3)
px4=(4,5,6)
P.addition1(px3,px4)
###########Matrix##############
# Program to add two matrices using nested loop
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1],
[6,7,3],
[4,5,9]]
result = [[0,0,0],
[0,0,0],
[0,0,0]]
for r in result:
print(r)
# Python program to
# demonstrate stack implementation
# using list
stack = []
print('Initial stack')
print(stack)
# uncommenting print(stack.pop())
# will cause an IndexError
# as the stack is now empty
SNAPSHOTS:
OUTPUT:
CONCLUSION: