0% found this document useful (0 votes)
12 views4 pages

E-Note 20111 Content Document 20240522095712AM

Uploaded by

hotelvlogger26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

E-Note 20111 Content Document 20240522095712AM

Uploaded by

hotelvlogger26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

USN No:

II Semester B.Tech. Mid Sem Examination - 2


Computer Science and Engineering
Course Title: Object Oriented Programming Course Code: 23EN1202
Duration:75 Mins. Date: 15.05.2024
Time: 2.30 to 3.45 Max Marks: 40
Scheme:

Q.No. Marks

Q. 1(a) def list_methods_demo(): 05


my_list = [1, 2, 3, 4, 5]
my_list.append(6)
print("Append method:", my_list)
my_list.extend([7, 8, 9])
print("Extend method:", my_list)
my_list.insert(2, 10)
print("Insert method:", my_list)
my_list.remove(3)
print("Remove method:", my_list)
popped_element = my_list.pop()
print("Popped element using pop method:", popped_element)

def tuple_methods_demo():
my_tuple = (1, 2, 3, 4, 5)
index = my_tuple.index(3)
print("Index of element 3:", index)
count = my_tuple.count(4)
print("Count of element 4:", count)

list_methods_demo()
tuple_methods_demo()
Q. 1(b) Definition and example for each file method – 5 x 1M = 5M 05

Q. 2(a) def count_word_frequency(filename): 05


word_frequency = {}
file = open(filename, 'r')
for line in file:
words = line.split()
for word in words:
word = word.strip(",.?!")
if word:
word_frequency[word] = word_frequency.get(word, 0) + 1
file.close()
print("Word Frequency:")
for word, frequency in word_frequency.items():
print(f"{word}: {frequency}")

filename = input("Enter the filename: ")


count_word_frequency(filename)
Q. 2(b) ERROR 02

i. ValueError: too many values to unpack 0.5 M

ii. TypeError: 'tuple' object does not support item assignment 0.5 M

iii. IndexError: list index out of range 0.5 M

iv. KeyError: 'd' 0.5 M

Q. 2(c) i. Output (2M) ii. Output (1M) 03


[2, 4, 6, 10, 12] {1, 2, 3, 4, 5, 6, 7, 8}
[2, 4, 6, 2, 4, 6] {1, 2, 3, 4, 5}
[2, 0, 4, 6]
[2, 0, 6]

Q. 3(a) Tel_ph={} #EMPTY DICTIONARY 05


print("How many insertions?")
n=int(input())
for i in range(n): #INSERTION
ph=int(input("Enter phone number: "))
name=input("Enter Name: ")
Tel_ph[ph]=name
print("Telphone Directory:\n",Tel_ph) #INITIAL DISPLAY

s=int(input("Enter key to search: ")) #SEARCH


if s in Tel_ph:
print("Key found and Its value is: ", Tel_ph[s])
else:
print("No key found")
s=int(input("Enter key to delete: ")) #DELETION
if s in Tel_ph:
del Tel_ph[s]
else:
print("No key found")
print("After deletion: ",Tel_ph) # FINAL DISPLAY
Q. 3(b) 05

Q. 4(a) class student: 05

def __init__(self,name,sem,college):
self.name=name
self.sem=sem
self.college=college

def display(self):
print(self.name,self.sem,self.college)

def __del__(self):
print("object deleted")

S1=student("RAM",4,"DSU")
S2=student("SAM",2,"DSU")

S1.display()
S2.display()
Q. 4(b) Class ABC: 05
def __init__(self, var1,var2):
self.var1=var1
self._var2=var2

def __display(self):
print(“Public variable value:”, self.var1)
print(“Private variable value:”, self._var2)

def show(self):
print(“Public variable value:”, self.var1)
print(“Private variable value:”, self._var2)

a. PRIVATE VARIABLE: _var2 PUBLIC VARIABLE: var1

b. PUBLIC METHOD: show(), PRIVATE METHOD: __display(),


SPECIAL METHOD: __init__()

c. A=ABC(10,20)

A._ABC__display() # THROUGH PRIVATE METHOD

A.show() # THROUGH PUBLIC METHOD

d. def help(self):
self.__display() #PUBLIC METHOD CALLING PRIVATE METHOD

A.help()

Date: 16.05.2024

Course Coordinator

(Dr. SRIDHAR S K)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy