cs pb1 ms
cs pb1 ms
cs pb1 ms
General Instructions:
● This question paper contains 37 questions.
● All questions are compulsory. However, internal choices have been provided in some
questions. Attempt only one of the choices in such questions
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.
SECTION A – 1 MARKS
1 State True or False 1
A user defined function in python can return more than one values.
Ans 1 True
2 Identify the output of the following code 1
print(True and 5>9 or not 4==4)
A) True
B) False
C) Error
D) None
Ans 2 B) False
3 What is the output of the following code 1
rem="how are you"
n=rem.find('Re')
print(n)
A) -1
B) 5
C) 6
D) Error
Ans 3 A) -1
4 What is the output of the following code 1
exam="IN the Year2025"
s1=exam[4:6].upper()
s2=exam[7:9]
s3=exam[-3:-6:-1]
print(s1,s2,s3)
A) THE Y 02
B) HE YE 02R
C) HE ye 02
D) HE Ye 02r
Ans 4 D) HE Ye 02r
5 What will be the output of the following code? 1
subject="INFORMATICS PRACTICES"
res=subject[-2:-12:-3]
print(res)
A) ECIT
B) ETRS
C) FORM
D) EIAP
Ans 5 B) ETRS
6 What will be the output of the following code? 1
t1=(2,4)
t2=(10,20,40,50)
res=t1[1]+t2[1:3]
print(res)
A) (4,20,40)
B) 4,20,40
C) None
D) Error
Ans 6 D) Error
7 Identify the output of the following Python statements. 1
color={1:"red",2:"blue",3:"orange",4:"blue"}
print(color.popitem())
A) (4, 'blue')
B) [4, 'blue']
C) 4
D) None of the above
Ans 7 A) (4, 'blue')
8 Identify the output of the following Python statements. 1
lst1 = [50, 165, 99, 77, 100,46]
lst1.insert( 2, 44)
lst1.insert( 5, 200)
print (lst1[-3])
A) 100
B) 46
C) 200
D) 99
Ans 8 C) 200
9 The table1 has attribute C1,C2,C3,C4,C5 of which C1 is primary key and C2,C4 are 1
alternate key. Find candidate keys.
A) C5, C7, C1
B) C1,C2,C4
C) C3,C5
D) C2,C4,C3,C5
Ans 9 B) C1,C2,C4
10 Somu is trying to write a tuple tup1 = (1,2,3,4,5) on a binary file hello.bin. Consider 1
the following code written by him.
import pickle
tup1 = (1,2,3,4,5)
myfile = open("test.bin",'wb')
pickle._______ #Statement 1
myfile.close()
OR
city=[‘mys’,’bgr’,’hub’,’has’,’bgm’]
a) To remove the last element .
b) To insert new city ‘mnd’ between ‘mys and ‘bgr’.
Ans a) gr1.index('B')
24 b) gr1.pop(3)
OR
a) city.pop(-1)
b) city.insert(1,”mnd”)
num=(4,5,9,6,22,3)
print(num)
print(separate_even(num)
Ans def separate_even(element):
26 t1=()
for a in element:
if a%2==0:
t1=t1+(a,)
return t1
num=(4,5,9,6,22,3)
print(num)
print(separate_even(num))
b) Primary key
OR
USE
1 mark for each correct answer
28 What is protocol ? Which protocol enables voice communication over internet ? 2
OR
State one advantage and one disadvantage of star topology.
Ans Protocols are a set of rules that are responsible for the communication of data
28 between various devices in the network.
VOIP – Voice over internet Protocol
(1 mark for each correct answer )
OR
Star topology – Advantage: Network remains operational even if one or two nodes
stops working or any other.
Disadvantage: Central node dependency or any other disadvantage.
(1 mark each for advantage and disadvantage )
SECTION C – 3 MARKS
29 Write a Python function SHOW_ID() which displays only the valid ID from the file 3
registration.txt . Valid ID contains 10 characters and starts with capital letter. The
registration.txt file contains registration numbers with one registration number per
line.
OR
Write a Python function to display the words from the file explore.txt whose length
is odd and starts with a vowel.
OR
def display_words():
file1=open("explore.txt","r")
words=file1.read().split()
for oneword in words:
if len(oneword)%2==1 and oneword[0].upper() in "AEIOU":
print(oneword)
file1.close()
30 Consider the stack INV_STACK that contains the inventory details stored as nested- 3
list. Each inventory record is represented as [item_name, cost, year] . Write the
following user-defined functions in Python to perform the
specified operations on the stack INV_STACK:
(I) push_ITEM(INV_STACK, ITEM): This function pushes the records into the
stack INV_STACK if the cost for each record is greater than Rs. 20000.
(II) pop_ITEM(INV_STACK): This function pops the topmost record from the
stack and returns it. If the stack is already empty, the function should display
"Underflow".
(III) peep(INV_STACK): This function displays the topmost element of the stack
without deleting it. If the stack is empty, the function should display 'None'.
OR
def pop_ITEM(INV_STACK):
if len(INV_STACK) < 0:
print("Underflow")
else:
print(INV_STACK.pop())
def peep(INV_STACK):
if len(INV_STACK) < 0:
print("None")
else:
print(INV_STACK[-1])
(3x1 mark for correct function body; No marks for any function header as it was a
part of the question)
OR
ITEM=[]
def push_product(product):
if product.startswith('a'):
ITEM.append(product)
def pop_even():
if len(ITEM)==0:
print("UNDERFLOW")
else:
return(ITEM.pop())
def Display():
if len(ITEM)==0:
print("NO ITEMS IN THE STACK - ITEM")
else:
print(ITEM)
(3x1 mark for correct function body; No marks for any function header as it was a
part of the question)
marks=[34,23,67,12,99,85]
for i in range(2,6):
for j in range(i,len(marks)):
if i+j > 6:
print(marks[j]+i)
OR
def modify(M,times):
for i in range(times):
if M[i]%3 == 0:
M[i]%=4
if M[i]%2 == 0:
M[i]*=2
arr = [45,65,23,91,42,60,25]
modify(arr,5)
for i in arr:
print(i,end="#")
87
102
88
103
89
90
½ marks for each correct output
Or
1#65#23#91#4#60#25#
½ marks for each number along with hash
SECTION D – 4 MARKS
32 Consider the table DOCTOR as given below 4
DOCTOR
Doc_id Doc_name Salary Deptno Age Place
3423 Anirudh 30000 10 42 Mysuru
1662 Deepak 45000 20 35 Bidar
8765 Ramu 60000 10 40 Hubli
4433 Abhilasha 90000 10 28 Mysuru
Note: The table contains many more records than shown here.
A) Write the following queries:
i. To display doc_id and doc_name in descending order of age.
ii. To display total salary whose deptno is 10.
iii. To display various place without repeating.
iv. To remove the doctor record whose doc_id is 1662.
OR
B) Write the ouput with respect to the table DOCTOR
i. Select count(*) from doctor where age>35;
ii. Select doc_name , place from doctor where place like “%i%”;
iii. Select deptno, sum(salary) from doctor group by deptno;
iv. Select place, doc_id from doctor where salary between 45000 and 65000;
Ans A)
32 i) Select doc_id, doc_name from DOCTOR
order by age desc;
ii) Select sum(salary) from DOCTOR
where deptno=10;
iii) Select distinct(place)
from DOCTOR
iv) delete from DOCTOR
where doc_id = 1662;
B)
i)
i. Select count(*) from doctor where age>35;
Doc_id Doc_name
3423 Anirudh
8765 Ramu
ii. Select doc_name , place from doctor where place like “%i%”
Doc_name Place
Deepak Bidar
Ramu Hubli
Deptno Sum(salary)
10 180000
20 45000
iv. Select place, doc_id from doctor where salary between 45000 and 65000.
Place Doc_id
Bidar 1662
Hubli 8765
33 A csv file "olympiad.csv" contains the data of a survey of participation. Each record 4
of the
file contains the following data:
• School id
• Name of school
• Total number of students in the school
• Number of students participated.
For example, a sample record of the file may be:
[1544, ‘BHGS’,3500,450]
Write the following Python functions to perform the specified operations on this
file:
(I) A function display() to display school name and number of students not
participated.
(II) A function countmore100() to count number of schools where participation is
more than 100.
Ans I)
33 def display():
file1=open("olympiad.csv")
cr=csv.reader(file1)
for rec in cr:
notParticipated=int(rec[2])-int(rec[3])
print(rec[1],notParticipated)
file1.close()
II)
def countmore100():
file1=open("olympiad.csv")
cr=csv.reader(file1)
count=0
for rec in cr:
if int(rec[3])>100:
count+=1
print("Participation more than 100 ",count)
file1.close()
PRODUCT
PID PNAME QTY PRICE SUPPCODE
23 Pendrive 100 450 SA05
45 DVD 3000 20 PS01
67 Laptop 30 24000 SA05
47 RAM 75 2500 CA11
SUPPLIER
SUPPCODE SUPPNAME RATING
SA05 INC INDIA 10
PS01 TECHNO 6
CA11 DIAMOND 8
cur=con.cursor()
book_no=int(input("Book number :"))
SECTION E – 5 MARKS
36 Mr. Keshav is organising national sports event and managing the data of various 5
school participated. For this he wants to store the following data of each school.
School id – integer
School name – string
Number of gold – integer
Number of silver – integer
Number of Bronze – integer
You have been assigned to complete the job with respect to the binary file sports.bin
where data is saved as lists.
i) Write a function to add details of new school along with medals won in
the file sports.bin.
ii) Write a function to display name of the school where number of golds in
more than 25.
iii) Write a function to display name of school and total medals won (
gold,silver,bronze) of all the schools.
Ans import pickle
36
def addrec():
file1=open("sports.bin","ab")
sid=int(input("School id "))
sname=input("School name ")
gold=int(input("Gold : "))
silver=int(input("Silver : "))
bronze=int(input("Bronze "))
rec=[sid,sname,gold,silver,bronze]
pickle.dump(rec,file1)
file1.close()
def gold25():
file1=open("sports.bin","rb")
print("Schools got gold more than 25")
try:
while True:
rec=pickle.load(file1)
if rec[2]>25:
print(rec[1])
except EOFError:
file1.close()
def school_total_medal():
file1=open("sports.bin","rb")
print("Schools and medals ")
try:
while True:
rec=pickle.load(file1)
total=rec[2]+rec[3]+rec[4]
print(rec[1],total,sep=' - ')
except EOFError:
file1.close()
37 HI TECH Company is setting up a secured network for its campus at Bengaluru for 5
operating their day-to-day office & web based activities. They are planning to have
network connectivity between four buildings. Answer the question (i) to (v) after
going through the building positions in the campus & other details which are given
below:
From To Distance
Admin Main 140
Admin Finance 85
Admin Academic 150
Finance Main 120
Finance Academic 45
Main Academic 70
BLOCK NUMBER OF
COMPUTER
Admin 50
Finance 20
Main 30
Academic 85
i. Suggest the most suitable block to house the server of the network with
reason.
ii. Draw a layout to efficiently connect all the blocks.
iii. Which device to be used to connect computers in each block.
iv. Suggest placement of repeater if needed as per layout with reason.
v. Hi Tech company Bengaluru is planning to connect to its other office at
Dharwad , which is more than 400 KM. Which type of network will be
formed. Justify your answer.
Ans i) Academic
37
ii)
*****