Ms Question Paper-2
Ms Question Paper-2
( COMPUTER SCIENCE)
Time allowed: 3 Hours Maximum Marks:
70
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 ( No marks
should be provided if student does not write the correct choice )
Ans : True
2. What id the output of following code snippet?
Ans : A ) GL-BALNETW-RK
3. Identify the output of the following code snippet:
text =
"The_quick_brown_fox"
(1)
index = text.find("quick")
result = text[:index].replace("_", "") +
text[index:].upper() print(result)
(A) Thequick_brown_fox
(B) TheQUICK_BROWN_FOX
Page: 1/25
(C) TheQUICKBROWNFOX
(D) TheQUICKBROWN_FOX
(A) 0
(B) -5
(C) 65
(D) 265
Ans : ( C ) 65
What will be the output of the following code snippet?
5.
(1)
text = "Python Programming"
print(text[1 : :3])
(A) Ph oai
(B) yoPgmn
(C) yhnPormig
(D) Pto rgamn
Ans : (B)
6. What will be the output of the following code?
tuple1 = (1, 2, 3)
tuple2 = tuple1 + (4,)
tuple1 += (5,)
print(tuple1, tuple2) (1)
Ans : C )
7. Dictionary my_dict as defined below, identify type of error raised by statement
my_dict['grape']?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
ValueError (1)
(B) TypeError
(C) KeyError
(D) ValueError
Ans : (C) KeyError
Page: 2/25
What does the list.pop(x) method do in Python?
8.
Ans : B. Removes the element at index x from the list and returns it.
Ans : C) 4
10. Fill in the blanks to complete the following code snippet
choosing the correct option:
(A) tell
(B) seek
(C) read
(D) write
Ans : False
Page: 3/25
12. What will be the output of the following
code? x = 4
def reset():
global
xx=
2
print(x, (1)
end='&') def
update():
x += 3
print(x, end='@')
update(
)x=6
reset()
print(x, end='$')
(A) 7@2&6$
(B) 7@6&6$
(C) 7@2&2$
(D) Error
Ans : (D) Error : Unbound local variable x in function
update()
Which SQL command can modify the structure of an existing table,
13. (1)
such as adding or removing columns?
Ans : (B) Both A and R are true and R is not the correct explanantion
for A
Page: 5/25
Assertion (A): A GROUP BY clause in SQL can be used without any
21.
aggregate functions.
Reasoning (R): The GROUP BY clause is used to group rows that (1)
have the
same values in specified columns and must always be
paired with aggregate functions.
Page: 6/25
Ans : ( C ) A is True , but R is False
( 1 marks + 1 Marks )
Ans :
Page: 7/25
If L1 = [10, 20, 30, 40, 20, 10, ...] and L2 = [5, 15, 25, ...], then:
24.
(Answer using builtin functions only)
II (A) : L1.extend(L2)
(B) : unique_elements = list(set(L1))
Page: 8/25
26. The code provided below is intended to reverse the order of
elements in a given list. However, there are syntax and logical
errors in the code. Rewrite it after removing all errors. Underline
all the corrections made.
def
reverse_list(lst) (2)
if not lst:
return lst
reversed_lst =
lst[::-1] return
reversed_lst
print("Reversed list: " reverse_list[1,2,3,4] )
Page: 9/25
(II)
A) Write an SQL command to drop the unique constraint
named unique_email from a column named email in a
table called Users.
OR
B) Write an SQL command to add a unique constraint to the
email column of an existing table named Users, ensuring that all
email addresses are unique.
Ans : (I)(A): Use the UNIQUE constraint along with the NOT NULL OR
PRIMARY KEY constraint.
OR
(B): Use the UNIQUE constraint alone, allowing for multiple NULL
values.
Example: column_name INT UNIQUE NULL
( 1 mark each for correct part for each questions any correct example
as an answer is acceptable )
Ans :
(A) : Advantage of Mesh Topology: High redundancy; if one connection
fails, data can still be transmitted through other nodes.
Disadvantage of Mesh Topology: Complexity and high cost; requires
more cabling and configuration compared to simpler topologies.
OR
Page: 10/25
29. A) Write a Python function that extracts and displays all the words present in a
text file “Vocab.txt” that begins with a vowel..
OR (3)
B) Write a Python function that extracts and displays all the
words containing a hyphen ("-") from a text file
"HyphenatedWords.txt", which has a three letter word before
hypen and four letter word after hypen. For example : “for-
them” is such a word.
Ans : A)
def display_words_starting_with_vowel():
vowels = 'AEIOUaeiou'
with open('Vocab.txt', 'r') as file:
words = file.read().split()
# Loop through the words and check if the first letter is a vowel
for word in words:
if word[0] in vowels:
print(word)
B)
def display_specific_hyphenated_words():
with open('HyphenatedWords.txt', 'r') as file:
words = file.read().split()
# Loop through the words and check if they match the pattern
for word in words:
parts = word.split('-')
# Check if the word is hyphenated and matches the format "XXX-
XXXX"
if len(parts) == 2 and len(parts[0]) == 3 and len(parts[1]) == 4:
print(word)
1/2 mark for file opening + 1/2 mark for correct loop +1/2 mark for
correct use of split( ) + 1 mark for correct condition + 1/2 mark
for output
OR
Write the function pop_odd() to pop the topmost number from the
stack and return it. If the stack is empty, the function should
display "Stack is empty".
For example:
If the integers input into the list NUMBERS are: [7, 12, 9, 4, 15]
Ans : (A )
def push_movie(movie_stack, new_movie): # 1 mark
movie_stack.append(new_movie)
def pop_movie(movie_stack):
Page: 12/25
return movie_stack.pop()
def peek_movie(movie_stack):
if not movie_stack: #1
return movie_stack[-1]
OR
if number % 2 != 0:
odd_numbers.append(number)
def pop_odd(odd_numbers):
return odd_numbers.pop()
def disp_odd(odd_numbers):
return "None"
return odd_numbers
Page: 13/25
31. Predict the output of the following code:
data = [3, 5, 7, 2]
result = ""
for num in data:
for i in range(num):
result += str(i) + "*"
result = result[:-1]
print(result)
OR
Ans : 0*1*2*0*1*2*3*4*0*1*2*3*4*5*6*0*1
( 1 mark for predicting correct output sequence of
numbers + 1 mark for predicting correct placement
of * + 1 mark for removing last * )
OR
0 +1 +
0 +1 +2 +
0 +1 +2 +3 +
( 1 MARK For putting output in three lines + 1 mark for
predicting correct sequence of numbers in each line (
1/2 for incorrect partially correct) + 1 mark for
correct placement of + )
Q No. Section-D ( 4 x 4 = 16 Marks) Marks
32. Consider the table ORDERS as given below
Note: The table contains many more records than shown here. (4)
A) Write the following queries:
(I) To display the total Quantity for each Product, excluding
Products with total Quantity less than 5.
Page: 14/25
(II) To display the ORDERS table sorted by total price in
descending order.
(III) To display the distinct customer names from the ORDERS
table.
Page: 15/25
(IV) To display the sum of the Price of all the orders for which the
quantity is NULL.
OR
B) Write the output:
(I) SELECT C_Name, SUM(Quantity) AS Total_Quantity FROM
ORDERS GROUP BY C_Name;
(II) SELECT * FROM ORDERS WHERE Product LIKE '%phone%';
(III) SELECT O_Id, C_Name, Product, Quantity, Price FROM
ORDERS WHERE Price BETWEEN 1500 AND 12000;
(IV) SELECT MAX(Price) FROM ORDERS;
OR
(B) ( 1 MARK EACH )
(I)
C_Name Total_Quantity
Jitendra 1
Mustafa 2
Dhwani 1
Alice 1
David NULL
(II)
O_Id C_Name Product Quantity Price
1002 Mustafa Smartphone 2 10000
1004 Alice Smartphone 1 9000
Page: 16/25
(III)
Name of a country
Life Expectancy (average number of years a person is
expected to live)
GDP per capita (Gross Domestic Product per person)
Percentage of population with access to healthcare
(4)
For example, a sample record of the file may be: ['Wonderland',
82.5, 40000, 95].
(I) Read all the data from the file in the form of a list and display all
those records for which the life expectancy is greater than 75.
Ans : (I)
import csv
def read_health_data(filename):
records = []
with open(filename, mode='r') as file:
reader = csv.reader(file)
next(reader) # Skip the header row if present
for row in reader:
country = row[0]
life_expectancy = float(row[1])
gdp_per_capita = float(row[2])
access_to_healthcare = float(row[3])
if life_expectancy > 75 :
records.append([country, life_expectancy, gdp_per_capita,
access_to_healthcare])
return records
Page: 17/25
(II)
def count_records( ):
records = read_health_data(“HealthData.csv”)
return len(records)
Page: 18/25
Alex has been tasked with managing the Student Database for a
34.
High School. He needs to access some information from the
STUDENTS and SUBJECTS tables for a performance evaluation.
Help him extract the following information by writing the desired
SQL queries as mentioned below.
Table: STUDENTS
FNam
S_ID Mark LName Enrollment_Date
e s
201 John Doe 15-09-2020 85
202 Jane Smith 10-05-2019 90 (4)
Johnso
203 Alex 22-11-2021 75
n
204 Emily Davis 30-01-2022 60
Micha
205 Brown 17-08-2018 95
el
Table: SUBJECTS
Ans : ( I )
SELECT * FROM STUDENTS S
JOIN SUBJECTS Sub ON S.S_ID = Sub.S_ID
WHERE S.Marks > 70;
Page: 19/25
(II)
SELECT *
FROM SUBJECTS
WHERE Credits BETWEEN 2 AND 4;
(III)
UPDATE SUBJECTS
SET Credits = Credits + 1
WHERE SubName LIKE '%Science%';
(IV) A:
SELECT FName, LName
FROM STUDENTS S
JOIN SUBJECTS Sub ON S.S_ID = Sub.S_ID
WHERE Sub.SubName =
'Mathematics'; OR
B:
SELECT *
FROM STUDENTS, SUBJECTS;
Field Type
productID int(11)
productName
varchar(20) price float
stockQty int(11)
(4)
Write the following Python function to perform the specified operation:
Ans :
import mysql.connector
def AddAndDisplay():
# Connect to the database
conn = mysql.connector.connect(
host='localhost',
user='root',
password='Electro123',
database='PRODUCTDB'
)
cursor = conn.cursor()
Page: 20/25
productID = int(input("Enter Product ID: "))
Ans : (I)
import pickle
def add_employee(filename):
employee_id = int(input("Enter Employee ID: "))
employee_name = input("Enter Employee Name: ")
position = input("Enter Position: ")
salary = float(input("Enter Salary: "))
new_employee = (employee_id, employee_name, position, salary)
with open(filename, 'ab') as file:
pickle.dump(new_employee, file)
Page: 21/25
(1/2 mark for input + 1 mark for correct use of dump( ) to add new emp
data)
(II)
def update_employee(filename):
employees = []
with open(filename, 'rb') as file:
try:
while True:
employees.append(pickle.load(file))
except EOFError:
pass
for i in range(len(employees)):
if employees[i][3] > 50000:
employees[i] = (employees[i][0], employees[i][1], "Team Lead",
employees[i][3])
with open(filename, 'wb') as file:
for employee in employees:
pickle.dump(employee, file)
(1 mark for correct use of load( ) method to retrieve data + 1/2 mark for
correct loop + 1/2 mark for correct condition within loop )
(III)
def display_non_team_leads(filename): print("\
nEmployees who are not Team Leads:") with
open(filename, 'rb') as file:
try:
while True:
employee = pickle.load(file)
if employee[2] != "Team Lead":
print(f"ID: {employee[0]}, Name: {employee[1]}, Position:
{employee[2]}, Salary: {employee[3]}")
except EOFError:
pass
( 1 mark for correct use of Try except block and 1/2 mark for correct
use of while loop )
Page: 22/25
Interstellar Logistics Ltd. is an international shipping company.
37. They are planning to establish a new logistics hub in Chennai, with
the head office in Bangalore. The Chennai hub will have four
buildings - OPERATIONS, WAREHOUSE, CUSTOMER_SUPPORT, and
MAINTENANCE. As a
network specialist, your task is to propose the best networking
solutions to address the challenges mentioned in points (I) to (V),
considering the distances between the various buildings and the
given requirements.
(5)
From To
Distance OPERATIONS
WAREHOUSE 40 m
OPERATIONS CUSTOMER_SUPPORT 90 m
OPERATIONS MAINTENANCE 50 m
WAREHOUSE CUSTOMER_SUPPORT 60 m
WAREHOUSE MAINTENANCE 45 m
CUSTOMER_SUPPORT MAINTENANCE 55 m
Location
Computers OPERATIONS 40
WAREHOUSE 20
CUSTOMER_SUPPORT 25
MAINTENANCE 22
BANGALORE HEAD OFFICE 15
Page: 23/25
(I) Suggest the most suitable location for the server within the
Chennai hub. Justify your decision.
a) Video Conferencing
b) Email
c) Telephony
d) Instant Messaging
OR
Ans :
(I) The server should be placed in the OPERATIONS
building. Justification:
Page: 24/25
CUSTOMER_SUPPORT
(90 m)
OPERATIONS
/ | \
/ | \
WAREHOUSE MAINTENANCE
( 1 mark )
(IV) A) The best option for live communication between the Chennai
Operations Office and the Bangalore Head Office would be Video
Conferencing. This allows real-time face-to-face meetings and
visual communication across long distances, which is ideal for
inter-office collaboration.
OR
(V) B) The network type in the Chennai hub would be a LAN (Local
Area Network), as all computers are located within a confined
geographical area (the logistics hub) and are connected to each other
for data communication within the same campus.
Page: 25/25