COMP. Sc. SAMPLE PAPER-2_MS
COMP. Sc. SAMPLE PAPER-2_MS
General Instructions:
2 (a) ['xy','yz'] 1
3 (a) False 1
4 (c) [9, 5, 6, 7, 8] 1
5 t 1
6 [3, 4] 1
7 012 1
8 (b) Removes the first occurrence of a specified value from the list 1
10 pickle 1
11 True 1
12 (d) Error 1
13 DROP TABLE 1
14 (b) COUNT 1
15 (a) SQL statements can not be typed in lowercase or uppercase letter. SQL statements are case 1
sensitive.
16 (b) Display records in increasing order of roll number 1
19 Circuit switching 1
20 (a) Both A and R are true and R is the correct explanation for A. 1
22 def reverseWordSentence(Sentence): 2
words = Sentence.spi1t( "")
return newSentence
(II) (A)T3 = T1 + T2
OR
(B) T2[::-l]
28 (i) Wi-Fi is a wireless communication technology that allows devices to connect to the internet 2
and exchange data without the need for physical cables. It uses radio waves to transmit
information between devices, enabling wireless internet access and network connectivity for
various devices like smartphones, laptops, and smart home devices.
(ii) In guided transmission media, cables (or wires) are used for communicating data while in
unguided transmission, in place of cables, signals travel through air.
OR
(i)Following are the three main types of computer networks, based upon the geographical
area as follows:
(a) Local Area Network (LAN)
(b) Metropolitan Area Network (MAN)
(c) Wide Area Network (WAN)
(ii) A switch is a networking device, which is used to connect different LAN segments of a
network. A switch also supports packet filtering and forwarding between LAN segments.
29 (A) 3
def write_urgent_lines():
try:
with open('Messages.txt', 'r') as input_file:
with open('UrgentLines.txt', 'w') as output_file:
for line in input_file:
if 'urgent' in line.lower():
output_file.write(line)
print("Urgent lines have been written to 'UrgentLines.txt'.")
except FileNotFoundError:
print("The file 'Messages.txt' was not found.")
OR
(B)
def count_lines_in_file():
try:
with open('Paragraph.txt', 'r') as file:
lines = file.readlines()
print(f"Number of lines in 'Paragraph.txt': {len(lines)}")
except FileNotFoundError:
print("The file 'Paragraph.txt' was not found.")
def pop(stack):
if len(stack) == 0:
return "Stack is empty"
return stack.pop()
def reverse_string(input_string):
stack = []
# Push all characters of the string into the stack
for char in input_string:
push(stack, char)
reversed_str = ""
# Pop characters from the stack to reverse the string
while len(stack) > 0:
reversed_str += pop(stack)
return reversed_str
# Example usage
input_string = "Hello"
print("Reversed string:", reverse_string(input_string))
OR
(A)
R={"0M":76, "JAI":45, "B0B":89, "AU": 65 , "ANU": 90, "TOM" :82}
def PUSH(S,N):
S.append(N)
def POP(S):
if S!=[]:
return S.popO
else:
return None
ST=[ ]
for k in R:
if R[k]>=75:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end="")
else:
break
(ii) To display a report listing BookTitle, Type and Price in descending order of price.
32 (A) 4
(I) select Product, sum(Quantity) from orders group by product having sum(Quantity)>=5;
(II) select * from orders order by Price desc;
(III) select distinct C_Name from orders;
(IV) select sum(price) as total_price from orders where Quantity IS NULL;
OR
B) (I)
C_Name | Total_Quantity
Jitendra | 1
Mustafa | 2
Dhwani | 1
(II)
O_Id | C_Name | Product | Quantity | Price
1002 | Mustafa | Smartphone | 2 | 10000
1003 | Dhwani | Headphone | 1 | 1500
(III)
O_Id | C_Name | Product | Quantity | Price
1001 | Jitendra | Laptop | 1 | 12000
1002 | Mustafa | Smartphone | 2 | 10000
1003 | Dhwani | Headphone | 1 | 1500
(IV)
MAX(Price)
12000
33 (I) Write a function to read all the data from the file and display all records, where the total 4
number of residents is less than 2000000:
import csv
def display_small_cities():
with open('HealthSurvey.csv', 'r') as file:
reader = csv.reader(file)
# Skip the header if present
next(reader)
for row in reader:
city = row[0]
residents = int(row[1])
if residents < 2000000:
print(row)
# Example Usage
display_small_cities()
import csv
def count_records():
reader = csv.reader(file)
next(reader)
# Convert the reader object to a list and count the number of rows
records = list(reader)
count = len(records)
# Example Usage
count_records()
35 def AddAndDelete(): 4
import mysql.connector as mycon
mydb=mycon.connect(host="localhost",user="root",passwd=" Pencil ", database=" ITEMDB
")
mycur=mydb.cursor()
no=int(input("Enter Student Admission Number: "))
nm=input("Enter Student Name: ")
pr=float(input("Enter percentage: "))
cls=int(input("Enter class: "))
query="INSERT INTO student VALUES ({},'{}',{},{});"
query=query.format(no,nm,pr,cls)
mycur.execute(query)
mydb.commit()
try:
mycur.execute("Delete from student where ItemName=„Pencil‟ ;")
mycur.commit()
except:
mydb.close()
36 (a) tell() method tells you the current position of cursor within the file. 5
Syntax: file_object.tell()
(b) import pickle
def AddRegistration() :
f=open("Registration.dat","ab")
ans='y'
rno=" "
sname=" " .
class=" "
Nos=0
while ans=='y':
rno=input("Enter registration no..")
sname=input("Enter student name ")
class=input("Enter class")
Nos=int(Inputt“Enter number of subjects :”))
reglst=[rno.sname,class,Nos]
pickle.dump(reglst,f)
ans=input("Continue(y/n)")
f.close()
def CountRegistrationst):
f=open("Registration.dat","rb")
count=0
try:
while True: -
phonelst=p1ckle.load(f)
count+=1
37 (i) B_TOWN can house the server as it has the maximum no. of computers. 5
(ii) Optical fibre cable is the best for this star topology.
(iii) Switch
(iv) VoIP
(v) MAN (Metropolitan Area Network) will be formed as network would span within a city.
OR
a) Video Conferencing