You are on page 1of 5

Daffodil International

University
Department of Computer Science and Engineering

Submited by:

Md Abu Ryan

Id: 202-15-14408

Section: A

Course Code: CSE-233

Course title: OOP-2


Ans to the question no -1(a)
class Student:

def __init__(self, name, rollno,marks):

self.name = name

self.rollno = rollno

self.marks = marks

def accept(self, Name, Rollno,marks):

ob = Student(Name, Rollno,marks)

ls.append(ob)

def display(self, ob):

print("Name : ", ob.name)

print("RollNo : ", ob.rollno)

print("marks in OOp-2 :",ob.marks)

print("\n")

def search(self, rn):

for i in range(ls.__len__()):

if (ls[i].rollno == rn):

return i

ls = []

obj = Student('', 0,'')obj.accept("Nur", 1,75)

obj.accept("Asif", 2,65)

obj.accept("abul", 3,99)

print("\n")

print("\nList of Students\n")
for i in range(ls.__len__()):

obj.display(ls[i])

print("Student Found : ")

s = obj.search(3)

obj.display(ls[s])

b)
In the programme above,we need to use exception handling in the searching part.Because we have a
limited data set and there is limited data stored.If a user tries to access a data through index which
actually doesn’t belong to our dataset or beyond our dataset it will show an error message to the
user.To fix this we should use exception handling in that part so that we can handle this through our
code.

c)
import numpy as np
lst=[]*3
for i in range(0,3):
ls1=[]
for j in range(0,3):
x=int(input())
ls1.append(x)
lst.append(ls1)
print(lst)array=np.array(lst)
matrix=array.reshape(3,3)
trans=matrix.transpose()
print(trans)

Ans to question -2(a)


class Time():
def __init__(self,hr,min):
self.hrs = hr
self.mins = min
def addTime(self,Time):
mins = self.hrs*60 + Time.hrs*60 + self.mins+Time.mins
return Time(mins//60,mins%60)
def displayTime(self):
print('{} hr {} mins'.format(self.hrs,self.mins))
def displayMinute(self):
print('{} minutes'.format(self.hrs*60+self.mins))
t1 = Time(2,50)
t2 = Time(1,20)
t3 = t1.addTime(t2)
t3.displayTime()
t3.displayMinute()b)
class Bird:
def intro(self):
print("There are different types of birds")
def flight(self):
print("Most of the birds can fly but some cannot")
class parrot(Bird):
def flight(self):
print("Parrots can fly")
class penguin(Bird):
def flight(self):
print("Penguins do not fly")
obj_bird = Bird()
obj_parr = parrot()
obj_peng = penguin()
obj_bird.intro()
obj_bird.flight()
obj_parr.intro()
obj_parr.flight()
obj_peng.intro()
obj_peng.flight()c)
class Abul:
def m(self):
print("Hi I am abul")
class Abul1(Abul):
pass
class Abul2(Abul):
def m(self):
print("I am Abul2")
class Abul3(Abul1, Abul2):
pass
obj =Abul3()
obj.m()

Ans to question no-3 (a)

names = ["Abul", "Jogga", "Mogga", "Koddu"]


try:
for name in range(len(names) + 1):
print(names[name])
except IndexError:
print("out of bound")

You might also like