SQP (CS XII) 2024 Edition

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

CBSE SAMPLE QUESTION PAPER (SOLVED)

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)

S.2 Computer Science with Python–XII


14. What will be the output of the query? (1)
SELECT * FROM products WHERE product_name LIKE 'App%';
(a) Details of all products whose names start with 'App'
(b) Details of all products whose names end with 'App'
(c) Names of all products whose names start with 'App'
(d) Names of all products whose names end with 'App'
Ans. (a) Details of all products whose names start with 'App'
15. In which datatype the value stored is padded with spaces to fit the specified length. (1)
(a) DATE (b) VARCHAR
(c) FLOAT (d) CHAR
Ans. (d) CHAR
16. Which aggregate function can be used to find the cardinality of a table? (1)
(a) sum() (b) count()
(c) avg() (d) max()
Ans. (b) count()
17. Which protocol is used to transfer files over the Internet? (1)
(a) HTTP (b) FTP
(c) PPP (d) HTTPS
Ans. (b) FTP
18. Which network device is used to connect two networks that use different protocols? (1)
(a) Modem (b) Gateway
(c) Switch (b) Repeater
Ans. (b) Gateway
19. Which switching technique breaks data into smaller packets for transmission, allowing multiple packets to
share the same network resources. (1)
Ans. Packet Switching
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): Positional arguments in Python functions must be passed in the exact order in which they are
defined in the function signature.
Reason (R): This is because Python functions automatically assign default values to positional
arguments.
(1)
Ans. (c) A is True but R is False.
21. Assertion (A): A SELECT command in SQL can have both WHERE and HAVING clauses.
Reason (R): WHERE and HAVING clauses are used to check conditions, therefore, these can be used
interchangeably.(1)
Ans. (c) A is True but R is False.

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)

Sample Question Paper S.3


23. Give two examples of each of the following:
(a) Arithmetic operators
(b) Relational operators (2)
Ans. (a) Arithmetic operators: +,-
(b) Relational operators: >, >=
24. If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
(Answer using built-in functions only)(2)
(a) (i) Write a statement to count the occurrences of 4 in L1.
OR
(ii) Write a statement to sort the elements of list L1 in ascending order.
(b) (i) Write a statement to insert all the elements of L2 at the end of L1.
OR
(ii) Write a statement to reverse the elements of list L2.
Ans. (a) (i) L1.count(4)
OR
(ii) L1.sort()
(b) (i) L1.extend(L2)
OR
(ii) L2.reverse()
25. Identify the correct output(s) of the following code. Also write the minimum and the maximum possible
values of the variable b. (2)
import random
a="Wisdom"
b=random.randint(1,6)
for i in range(0,b,2):
   print(a[i],end='#')
(a) W# (b) W#i#
(c) W#s# (d) W#i#s#
Ans. (a), (c)
Minimum and maximum possible values of the variable b: 1,6
26. The code provided below is intended to swap the first and last elements of a given tuple. However, there are
syntax and logical errors in the code. Rewrite it after removing all errors. Underline all the corrections made.
(2)
def swap_first_last(tup)
         if len(tup) < 2:
         return tup
      new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
        return new_tup
result = swap_first_last((1, 2, 3, 4))
print("Swapped tuple: " result)
Ans. def swap_first_last(tup):
         if len(tup) < 2:
          return tup
      new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
        return new_tup
result = swap_first_last((1, 2, 3, 4))
print("Swapped tuple: ", result)

S.4 Computer Science with Python–XII


27. (a) (i) What constraint should be applied on a table column so that duplicate values are not allowed in that
column, but NULL is allowed. (2)
OR
(ii) What constraint should be applied on a table column so that NULL is not allowed in that column, but
duplicate values are allowed.
(b) (i) Write an SQL command to remove the Primary Key constraint from a table, named MOBILE. M_ID is the
primary key of the table.
OR
(ii) Write an SQL command to make the column M_ID the Primary Key of an already existing table, named
MOBILE.
Ans. (a) (i) UNIQUE
OR
(ii) NOT NULL
(b) (i) ALTER TABLE MOBILE DROP PRIMARY KEY;
OR
(ii) ALTER TABLE MOBILE ADD PRIMARY KEY (M_ID);
28. (a) List one advantage and one disadvantage of star topology. (2)
OR
(b) Expand the term SMTP. What is the use of SMTP?
Ans. (a) Advantage: Network extension is easy.
Disadvantage: Failure of switch/hub results in failure of the network.
OR
(b) SMTP: Simple Mail Transfer Protocol.
SMTP is used for sending e-mails from client to server.

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".

Sample Question Paper S.5


(iii) peep(BooksStack): This function displays the topmost element of the stack without deleting it.
If the stack is empty, the function should display 'None'.
OR
(b) Write the definition of a user-defined function ‘push_even(N)’ which accepts a list of integers in a
parameter ‘N’ and pushes all those integers which are even from the list ‘N’ into a Stack named
‘EvenNumbers’.
Write function pop_even() to pop the topmost number from the stack and returns it. If the
stack is already empty, the function should display "Empty".
Write function Disp_even() to display all element of the stack without deleting them. If the
stack is empty, the function should display 'None'.
For example:
If the integers input into the list ‘VALUES’ are:
[10, 5, 8, 3, 12]
Then the stack ‘EvenNumbers’ should store:
[10, 8, 12]
Ans. (a) (i) def push_book(BooksStack, new_book):
  BooksStack.append(new_book)
(ii) def pop_book(BooksStack):
   if not BooksStack:
    print("Underflow")
  else:
    return(BooksStack.pop())
(iii) def peep(BooksStack):
   if not BooksStack:
    print("None")
  else:
    print(BooksStack[-1])
OR
(b) def push_even(N):
   EvenNumbers = []
   for num in N:
     if num % 2 == 0:
      EvenNumbers.append(num)
  return EvenNumbers
VALUES = []
for i in range(5):
   VALUES.append(int(input("Enter an integer: ")))
EvenNumbers = push_even(VALUES)
def pop_even():
   if not EvenNumbers:
    print("Underflow")
  else:
    print(EvenNumbers.pop())
pop_even()
def Disp_even():
   if not EvenNumbers:
    print("None")
  else:
    print(EvenNumbers[-1])
Disp_even()

S.6 Computer Science with Python–XII


31. Predict the output of the following code: (3)
d = {"apple": 15, "banana": 7, "cherry": 9}
str1 = ""
for key in d:
    str1 = str1 + str(d[key]) + "@" + “\n”
str2 = str1[:-1]
print(str2)
OR
Predict the output of the following code: (3)
line=[4,9,12,6,20]
for I in line:
  for j in range(1,I%5):
  print(j,'#',end="")
  print()
Ans. (a) 15@
7@
9
OR
(b) 1 #2 #3#
1 #2 #3 #
1 #

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

Sample Question Paper S.7


(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. 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.

S.8 Computer Science with Python–XII


34. Saman has been entrusted with the management of Law University Database. He needs to access some
information from FACULTY and COURSES tables for a survey analysis. Help him extract the following
information by writing the desired SQL queries as mentioned below. (4)
Table: FACULTY
F_ID FName LName Hire_Date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
Table: COURSES
C_ID F_ID CName Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000
(a) To display complete details (from both the tables) of those Faculties whose salary is less than 12000.
(b) To display the details of courses whose fees is in the range of 20000 to 50000 (both values included).
(c) To increase the fees of all courses by 500 which have "Computer" in their Course names.
(d) (i) To display names (FName and LName) of faculty taking System Design.
OR
(ii) To display the Cartesian Product of these two tables.
Ans. (a) Select * from FACULTY natural join COURSES where Salary<12000;
OR
Select * from FACULTY, COURSES where Salary<12000 and facuty.f_id=courses.f_
id;
(b) Select * from courses where fees between 20000 and 50000;
(c) Update courses set fees=fees+500 where CName like '%Computer%';
(d) (i) Select FName, LName from faculty natural join courses where Came="System
Design";
OR
Select FName, LName from faculty, courses where Came="System Design" and
facuty.f_id=courses.f_id;
OR
(ii) Select * from FACULTY, COURSES;
35. A table, named STATIONERY, in ITEMDB database, has the following structure: (4)
Field Type
itemNo int(11)
itemName varchar(15)
price float
qty int(11)
Write the following Python function to perform the specified operation:
AddAndDisplay(): To input details of an item and store it in the table STATIONERY. The function should then
retrieve and display all records from the STATIONERY table where the Price is greater than 120.
Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Pencil

Sample Question Paper S.9


Ans. def AddAndDisplay():
   import mysql.connector as mycon
    mydb=mycon.connect(host="localhost",user="root",
    passwd="Pencil",database="ITEMDB")
    mycur=mydb.cursor()
   no=int(input("Enter Item Number: "))
   nm=input("Enter Item Name: ")
   pr=float(input("Enter price: "))
   qty=int(input("Enter qty: "))
   query="INSERT INTO stationery VALUES ({},'{}',{},{})"
    query=query.format(no,nm,pr,qty)
    mycur.execute(query)
    mydb.commit()
   mycur.execute("select * from stationery where price>120")
   for rec in mycur:
     print(rec)

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:

S.10 Computer Science with Python–XII


     with open('candidates.bin', 'rb') as file:
        while True:
         try:
           candidate = pickle.load(file)
           if candidate[3] > 10: # If experience > 10 years
             candidate[2] = 'Senior Manager'
           updated_candidates.append(candidate)
         except EOFError:
           break # End of file reached
   except FileNotFoundError:
     print("No candidate data found. Please add candidates first.")
    return
   with open('candidates.bin', 'wb') as file:
     for candidate in updated_candidates:
        pickle.dump(candidate, file)
   print("Candidates updated to Senior Manager where applicable.")
update_senior_manager()
(c) import pickle
def display_non_senior_managers():
    try:
     with open('candidates.bin', 'rb') as file:
        while True:
         try:
           candidate = pickle.load(file)
           if candidate[2] != 'Senior Manager': # Check if not Senior
Manager
             print(f"Candidate ID: {candidate[0]}")
             print(f"Candidate Name: {candidate[1]}")
             print(f"Designation: {candidate[2]}")
             print(f"Experience: {candidate[3]}")
             print("--------------------")
         except EOFError:
           break # End of file reached
   except FileNotFoundError:
     print("No candidate data found. Please add candidates first.")
display_non_senior_managers()
37. Event Horizon Enterprises is an event planning organization. It is planning to set up its India campus in Mumbai
with its head office in Delhi. The Mumbai campus will have four blocks/buildings - ADMIN, FOOD, MEDIA,
DECORATORS. You, as a network expert, need to suggest the best network-related solutions for them to
resolve the issues/problems mentioned in points (I) to (V), keeping in mind the distances between various
blocks/buildings and other given parameters. (5)

MUMBAI
DELHI
ADMIN

FOOD
HEAD
MEDIA OFFICE

DECORATORS

Sample Question Paper S.11


Block to Block distances (in Mtrs.)
From To Distance
ADMIN FOOD 42 m
ADMIN MEDIA 96 m
ADMIN DECORATORS 48 m
FOOD MEDIA 58 m
FOOD DECORATORS 46 m
MEDIA DECORATORS 42 m

Distance of Delhi Head Office from Mumbai Campus = 1500 km


Number of computers in each of the blocks/Center is as follows:
ADMIN 30
FOOD 18
MEDIA 25
DECORATORS 20
DELHI HEAD OFFICE 18

(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

Cable: Coaxial cable


(d) There is no requirement of the Repeat as the optical fibre cable used for the network can carry the data
to much longer distances than within the campus.
(e) (i) I. Videoconferencing
OR
(ii) LAN

S.12 Computer Science with Python–XII

You might also like