XII COMP SCI MQP 13
XII COMP SCI MQP 13
XII COMP SCI MQP 13
[1]
print(Str1[-5:10:-3])
6 What will be the output of the following code?
tup = (5,)
result = [tup] * 3
print(result) 1
A. [5, 5, 5] B. (5,), (5,), (5,)
C. [(5,), (5,), (5,)] D. Error
7 What will be the output of the following code?
data_dict = {'m': 3, 'n': 7}
data_dict['o'] = 4
1
print(data_dict)
A. {'m': 3, 'n': 7, 'o': 4} B. KeyError
C. {'m': 3, 'n': 7, 'o': 11} D. ValueError
8 What does the str.find(sub) method do?
A. Returns the first occurrence of the substring in the string
B. Returns the last occurrence of the substring in the string 1
C. Replaces all occurrences of the substring with another string
D. Counts the number of occurrences of the substring in the string
9 In a library management system, consider a Books table and an Authors table. The
Books table has a foreign key Author_ID that references the primary key Author_ID
in the Authors table.
What does this foreign key relationship ensure?
1
A. Each book must have a corresponding author listed in the Authors table.
B. Authors cannot exist without having written any books.
C. Every author is required to have at least one book associated with them.
D. Books can be added to the system without linking them to an author.
10 What is the primary use of the dump() function in Python?
A. To load data from a file into memory.
B. To serialize an object and write it to a file. 1
C. To deserialize an object and write it to a file.
D. To read a file and return its content.
11 When denominator of a division expression is zero___________ Exception is raised. 1
12 What will be the output of the following code?
c = 10
def update_value(value):
global c
if value % 2 == 0:
c += value * 2
else: 1
c += value
print(c ,end=' | ')
update_value(4)
update_value(7)
A. 8|7| B.18|17|
C.17|18| D.18|25|
13 Which SQL command can change the cardinality of an existing relation? 1
14 In which scenario will the following SQL statement return results? 1
SELECT gender, COUNT(*) FROM students GROUP BY gender HAVING COUNT(*) >
3;
A. When there are more than three students of any gender.
B. When the total number of students is greater than three.
[2]
C. When each gender group has more than three members.
D. When the average age of students is greater than three.
15 In SQL, which command is used to modify existing records in a table?
A. MODIFY B. UPDATE 1
C. CHANGED. ALTER
16 Which aggregate function is used to determine the total number of rows in a table?
A. sum() B. count() 1
C. avg() D. max()
17 Which statement is used to exit a function and return a value?
A. end B. return 1
C. exit D. break
18 Which of the following cables carry data signals in the form of light?
A. Coaxial B. Fiber-optic 1
C. Twisted pair D. All of the these
19 Which switching method is commonly used in Voice over IP (VoIP)
communications?
1
A. Circuit switching B. Packet switching
C. Message switching D. Store-and-forward
Q20 and Q21 are Assertion(A) and Reason(R) based questions. Mark the correct
choice as:
A.Both A and R are true and R is the correct explanation for A
B.Both A and R are true and R is not the correct explanation for A
C.A is True but R is False
D.A is False but R is True
20 Assertion(A): Hub is a broadcast device and Switch is a unicast device.
Reason(R): Hub forwards data to all devices, whereas Switch maintains a MAC 1
address table to send data only to the intended device.
21 Assertion(A): The GROUP BY clause is used to group rows that have the same
values into summary rows. 1
Reason(R): GROUP BY is always used with the ORDER BY clause
Q. No. Section – B (7 x 2=14 Marks) Marks
22 Write a function reverse_words(sentence) that takes a sentence (string) as input 2
and returns a new sentence with the words in reverse order.
For example, if the input is "Python is fun", the function should return "fun is
Python"
23 Predict the output of the following code: 2
lst=[2,4,6]
a=[]
for i in range(0,3):
lst[i-1]=lst[i]
a.append(lst[i-1])
for i in range(0,3):
print(lst[i],end=' ')
print()
for i in range(0,3):
print(a[i],end=' ')
24 A) Consider the following list of elements and write Python statement to print the 2
output of each question.
elements=['apple',200,300,'red','blue','grapes']
i) print(elements[3:5])
OR
[3]
ii) print(elements[::-1]
B) Consider the following list exam and write Python statement for the following
questions:
exam=[‘english’,’physics’,’chemistry’,’cs’,’biology’]
i) To insert subject “maths” as last element
OR
ii) To display the list in reverse alphabetical order
25 Identify the correct output(s) of the following code. Also write the minimum and 2
the maximum possible values of the variable b.
import random
sentence = "Coding with Python"
words =sentence.split()
b = random.randint(1, 2)
for i in range(b):
print(len(words[i]), end=', ')
A. 6 B. 6,
C. 6,4,6 D. 6,4,6,
26 The code given below accepts a number as an argument and returns the list of all 2
prime numbers upto that number. Observe the following code carefully and rewrite
it after removing all syntax and logical errors. Underline all the corrections made.
define prime(num):
for i in range(2,n/2+1,1):
if i%num==0:
print(‘Not prime’)
continue
else:
print(‘Prime’)
27 (I) 2
A. What SQL constraint should be used to define a default value for a column if
no specific value is provided when inserting a new record?
OR
B. In SQL, which constraint enforces a relationship between columns in
different tables by ensuring that values in the child table correspond to
values in the parent table?
(II)
A) What type of constraint would you use to ensure that a column's value must
match a specified pattern (e.g., a valid email address format)?
OR
B) Which constraint ensures that the values in a column or group of columns
are unique across the table, but can still allow NULL values?
28 (I) 2
A. Expand the following abbreviations:
(i)POP (ii)HTTPS
B. What is a URL?
OR
(II)Write two points of difference between Circuit Switching and Packet Switching
Q. No. Section – C (3 x 3 = 9 Marks) Marks
29 A) Write a Python function that extracts all unique words from a text file 3
"Unique_Words.txt" and writes them to a new file "Unique_Output.txt".
OR
[4]
B) Write a Python function that reads the content of a text file "Sentences.txt"
and prints all the lines that are longer than 20 characters.".
30 A)You are given a nested list CityList where each element is a list representing a city
record in the format [CityName, Country, Population]. Write the following Python
functions to manipulate the stack MustVisitCities.
(i) Push_element(CityList, MustVisitCities): Push the city records where the
population is more than 1 million.
(ii) Pop_element(MustVisitCities): Pop and display the city records until the stack is
empty, and print "Stack Empty" afterward.
For example: If the nested list contains the following data:
CityList = [['New York', 'USA', 8.4], ['Tokyo', 'Japan', 9.3],['Zurich', 'Switzerland', 0.8],
['Delhi', 'India', 18.6]]
The stack should contain:
[['New York', 'USA', 8.4], ['Tokyo', 'Japan', 9.3],['Delhi', 'India', 18.6]]
OR
B) Consider a Nested List ‘Inventory’ in which all the elements are lists of the
format – [ItemID, ItemName, Price, Quantity]. Write the following user defined
functions in python to perform the task specified on the stack named ‘items’ which
is initially an empty list.
• Push_item(Inventory) – It takes nested list Inventory as argument and pushes
3
records of those items onto stack which have quantity > 100.
• Pop_items() –It repeatedly pops the top element of stack and displays it.
Appropriate message should be displayed when there are no more elements left in
the stack.
For example, if
Inventory = [[101, ‘Pen’, 10, 120],
[102, ‘Pencil’, 10, 100],
[103, ‘Eraser’, 5, 90],
[104, ‘Notebook’, 20, 52],
[105, ‘Marker’, 30, 130],
[106, ‘Sharpener’, 5, 110],]
After execution of Push_Items(Inventory), Stack should contain:
[[101, ‘Pen’, 10, 120], [105, ‘Marker’, 30, 130], [106, ‘Sharpener’, 5, 110]] Top
The output after Pop_Items() should be:
[106, ‘Sharpener’, 5, 110]
[105, ‘Marker’, 30, 130]
[101, ‘Pen’, 10, 120]
Stack Empty
31 Predict the output of the following code: 3
(i)
s = "Le@rn@Python#24"
m = ""
for i in range(len(s)):
if s[i].isupper():
m=m+s[i]
elif s[i].islower():
m=m+s[i].upper()
elif i % 2 != 0:
m += s[i] * 2
else:
m += s[i-1]
print(m)
[5]
OR
Predict the output of the following code:
(ii)
x = 25
def modify(s, c=2):
global x
for a in s:
if a in 'qweIOP':
x //= 5
print(a.upper(),'@',c*x)
else:
x += 5
print(a.lower(),'#',c+x)
string = 'Pytho'
modify(string,10)
print(x, '$', string)
Table: Vehicle 4
CODE VTYPE PERKM
101 VOLVO BUS 160
102 AC DELUXE BUS 150
103 ORDINARY BUS 90
105 SUV 40
104 CAR 20
a. To display NO, NAME, TDATE from the table Travel in descending order of NO.
b. To display the NAME of all the travelers from the table Travel who are travelling
by vehicle with code 101 or 102.
c. To display the NO and NAME of those travellers from the table Travel who
travelled between ‘2015-12-31’ and ‘2016-04-01’.
d. To display the CODE, NAME, VTYPE from both the tables with distance travelled
(km) less than 90 Km.
OR
e. To display the NAME of those traveller whose name starts with the alphabet ‘R’.
35 A table, named Electronics, in shopdb database, has the following structure:
4
Write a Python function UpdateStock() to update the quantity of a product in the
ELECTRONICS table based on the product ID. After updating, display all products
where the price is greater than 5000.
Assume the following for Python-Database connectivity: Database: SHOPDB, Host:
localhost, User: admin, Password: Gadget123
Q. No. Section – E (2 x 5 = 10 Marks) Marks
36 You are provided with an employee record stored in a binary file named 5
[7]
employees.dat. Each record contains the following details of an employee:
[Emp_ID,Emp_Name, Department, Salary]
• Emp_ID (integer): Unique ID of the employee
• Emp_Name (string): Name of the employee
• Department (string): Department in which the employee works
• Salary (float): Current salary of the employee
(I)Write a function to input the data of an employee and append it in a binary file.
(II) Write a Python function that read the employee records from the binary file
employees.dat. Check if the salary of each employee is less than 50,000. If the
salary is less than 50,000, increase the salary by 10%.Update the records in the
binary file with the modified salary values
37 ABC Computers decided to open a new office at Banglore, the office consist of Five
Buildings and each contains number of computers. The details are shown below.
Computers in each building are networked but buildings are not networked so far.
The Company has now decided to connect building also.
[8]