SQP (CS XII) 2024 Edition
SQP (CS XII) 2024 Edition
SQP (CS XII) 2024 Edition
CLASS XII
COMPUTER SCIENCE (083)
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.
Section A
1. State True or False: (1)
The Python interpreter handles logical errors during code execution.
Ans. False
2. Identify the output of the following code snippet: (1)
text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)
(a) #THONPROGRAM (b) ##THON#ROGRAM
(c) #THON#ROGRAM (d) #YTHON#ROGRAM
Ans. (a) #THONPROGRAM
3. Which of the following expressions evaluates to False? (1)
(a) not(True) and False (b) True or False
(c) not(False and True) (d) True and not(False)
Ans. (a) not(True) and False
4. What is the output of the expression? (1)
country='International'
print(country.split("n"))
(a) ('I', 'ter', 'atio', 'al')
(b) ['I', 'ter', 'atio', 'al']
(c) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
(d) Error
Ans. (b) ['I', 'ter', 'atio', 'al']
5. What will be the output of the following code snippet? (1)
message= "World Peace"
print(message[-2::-2])
Ans. ce lo
6. What will be the output of the following code?(1)
tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(a) True (b) False
(c) tuple1 (d) Error
Ans. (b) False
7. If my_dict is a dictionary as defined below, then which of the following statements will raise an exception?
(1)
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
(a) my_dict.get('orange') (b) print(my_dict['apple', 'banana'])
(c) my_dict['apple']=20 (d) print(str(my_dict))
Ans. (b) print(my_dict['apple', 'banana'])
8. What does the list.remove(x) method do in Python? (1)
(a) Removes the element at index x from the list
(b) Removes the first occurrence of value x from the list
(c) Removes all occurrences of value x from the list
(d) Removes the last occurrence of value x from the list
Ans. (b) Removes the first occurrence of value x from the list
9. If a table which has one Primary key and two alternate keys. How many Candidate keys will this table
have?(1)
(a) 1 (b) 2
(c) 3 (d) 4
Ans. (c) 3
10. Write the missing statement to complete the following code: (1)
file = open("example.txt", "r")
data = file.read(100)
____________________ #Move the file pointer to the beginning of the file
next_data = file.read(50)
file.close()
Ans. file.seek(0) ( OR file.seek(0,0) )
11. State whether the following statement is True or False: (1)
The finally block in Python is executed only if no exception occurs in the try block.
Ans. False
12. What will be the output of the following code? (1)
c = 10
def add():
global c
c = c + 2
print(c,end='#')
add()
c=15
print(c,end='%')
(a) 12%15# (b) 15#12%
(c) 12#15% (d) 12%15#
Ans. (c) 12#15%
13. Which SQL command can change the degree of an existing relation? (1)
Ans. Alter (or Alter Table)
Section B
22. How is a mutable object different from an immutable object in Python?
Identify one mutable object and one immutable object from the following:
(1,2), [1,2], {1:1,2:2}, ‘123’ (2)
Ans. A mutable object can be updated whereas an immutable object cannot be updated.
Mutable object: [1,2] or {1:1,2:2} (Any one)
Immutable object: (1,2) or ‘123’ (Any one)
Section C
29. (a) Write a Python function that displays all the words containing @cmail from a text file “Emails.txt”. (3)
OR
(b) Write a Python function that finds and displays all the words longer than 5 characters from a text file
"Words.txt".
Ans. (a) def show():
f=open("Email.txt",'r')
data=f.read()
words=data.split()
for word in words:
if '@cmail' in word:
print(word,end=' ')
f.close()
OR
(b) def display_long_words():
with open("Words.txt", 'r') as file:
data=file.read()
words=data.split()
for word in words:
if len(word)>5:
print(word,end=' ')
30. (a) You have a stack named BooksStack that contains records of books. Each book record is represented as a
list containing book_title, author_name, and publication_year.
Write the following user-defined functions in Python to perform the specified operations on the stack
BooksStack:(3)
(i) push_book(BooksStack, new_book): This function takes the stack BooksStack and a new book record
new_book as arguments and pushes the new book record onto the stack.
(ii) pop_book(BooksStack): This function pops the topmost book record from the stack and returns it.
If the stack is already empty, the function should display "Underflow".
Section D
32. Consider the table ORDERS as given below (4)
O_Id C_Name Product Quantity Price
1001 Jitendra Laptop 1 12000
1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500
Note: The table contains many more records than shown here.
(a) Write the following queries:
(i) To display the total Quantity for each Product, excluding Products with total Quantity less than 5.
(ii) To display the orders table sorted by total price in descending order.
(iii) To display the distinct customer names from the Orders table.
(iv) Display the sum of 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;
Ans. (a) (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;
(b) (i)
C_Name Total_Quantity
Jitendra 1
Mustafa 2
Dhwani 1
(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. A csv file "Happiness.csv" contains the data of a survey. Each record of the file contains the following data:
● Name of a country
● Population of the country
● Sample Size (Number of persons who participated in the survey in that country)
● Happy (Number of persons who accepted that they were Happy)
For example, a sample record of the file may be:
[‘Signiland’, 5673000, 5000, 3426]
Write the following Python functions to perform the specified operations on this file: (4)
(a) Read all the data from the file in the form of a list and display all those records for which the population
is more than 5000000.
(b) Count the number of records in the file.
Ans. (a) def show():
import csv
f=open("happiness.csv",'r')
records=csv.reader(f)
next(records, None) #To skip the Header row
for i in records:
if int(i[1])>5000000:
print(i)
f.close()
(b) def Count_records():
import csv
f=open("happiness.csv",'r')
records=csv.reader(f)
next(records, None) #To skip the Header row
count=0
for i in records:
count+=1
print(count)
f.close()
Note (for both parts (a) and (b):
(a) Ignore import csv as it may be considered the part of the complete program, and there is no need to
import it in individual functions.
(b) Ignore next(records, None) as the file may or may not have the Header Row.
Section E
36. Surya is a manager working in a recruitment agency. He needs to manage the records of various candidates.
For this, he wants the following information of each candidate to be stored: (5)
Candidate_ID – integer
Candidate_Name – string
Designation – string
Experience – float
You, as a programmer of the company, have been assigned to do this job for Surya.
(a) Write a function to input the data of a candidate and append it in a binary file.
(b) Write a function to update the data of candidates whose experience is more than 10 years and change
their designation to "Senior Manager".
(c) Write a function to read the data from the binary file and display the data of all those candidates who are
not "Senior Manager".
Ans. (a) import pickle
def input_candidates():
candidates = []
n = int(input("Enter the number of candidates you want to add: "))
for i in range(n):
candidate_id = int(input("Enter Candidate ID: "))
candidate_name = input("Enter Candidate Name: ")
designation = input("Enter Designation: ")
experience = float(input("Enter Experience (in years): "))
candidates.append([candidate_id,candidate_name,designation,experience])
return candidates
candidates_list = input_candidates()
def append_candidate_data(candidates):
with open('candidates.bin', 'ab') as file:
for candidate in candidates:
pickle.dump(candidate, file)
print("Candidate data appended successfully.")
append_candidate_data(candidates_list)
(b) import pickle
def update_senior_manager():
updated_candidates = []
try:
MUMBAI
DELHI
ADMIN
FOOD
HEAD
MEDIA OFFICE
DECORATORS
(a) Suggest the most appropriate location of the server inside the MUMBAI campus. Justify your choice.
(b) Which hardware device will you suggest to connect all the computers within each building?
(c) Draw the cable layout to efficiently connect various buildings within the MUMBAI campus. Which cable
would you suggest for the most efficient data transfer over the network?
(d) Is there a requirement of a repeater in the given cable layout? Why/ Why not?
(e) (i) What would be your recommendation for enabling live visual communication between the Admin
Office at the Mumbai campus and the DELHI Head Office from the following options:
I. Videoconferencing
II. Email
III. Telephony
IV. Instant Messaging
OR
(ii) What type of network (PAN, LAN, MAN or WAN) will be set up among the computers connected in the
MUMBAI campus?
Ans. (a) ADMIN Block as it has the maximum number of computers.
(b) Switch
(c) MUMBAI
ADMIN
FOOD
MEDIA
DECORATORS