Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 12 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 12 with Solutions
Time: 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 the case of MCQ, the text of the correct answer should also be written.
Section A
(21 × 1 = 21)
Question 1.
State True or False:
Arguments are used to pass the reference of a variable to a function.
Answer:
False
Question 2.
Find the output of the following code.
Name="PythoN3@1" R=" " for x in range(len(Name)): if Name[x].isupperf): R=R+Name[x].lower() elif Name[x].islower(): R=R+Name[x].upper() elif Name[x].isdigit(): R=R+Name[x-1] else: R=R+"#" print(R)
(a) pYTHOn##@
(b) pYTHOnN#@
(c) pYTHOn#@
(d) pYTHOnN@#
Answer:
(b) pYTHOnN#®
Question 3.
Which of the following evaluates to True?
(a) True and Not True
(b) False or Not True and False
(c) Not True or Not 7%2
(d) None of these
Answer:
(d) None of these
Question 4.
Given: s=”ComputerExam”. What will be the output of
print(s[2]+s[8]+s[1:5])?
(a) mEOMUU
(b) mEompu
(c) mEomPU
(d) MEompu
Answer:
(b) mEompu
Question 5.
What will be the output of the following code snippet:
S="Exams@2025" print(S[-2 : 2 : -2]
Answer:
22s
Question 6.
Which of the following will be the output of the statement given below?
print([12, 34, 56, 78, 90] . pop())
(a) 78
(b) 90
(c) 12
(d) 12, 34, 56, 78, 90
Answer:
(b) 90
Question 7.
The following Python code will generate a _____________ type exception.
lst = [1, 2, 3] lst[3]
Answer:
IndexError: list index out of range
Question 8.
List, dictionary and sets are
(a) mutable
(b) immutable
(c) Both (a) and (b)
(d) None of these
Answer:
(a) mutable
Question 9.
What is the output of the following code?
num=4+float(7)/int(2.0) print("num=", num)
(a) num = 7.5
(b) 7.5
(c) num: 7.5
(d) Error
Answer:
(a) num=7.5
Question 10.
Write the missing statement to complete the following code:
f=open("readme.txt","r") s=_____________ # To read the entire contents of the file. Slst=s.split() for w in Slst: print(w)
Answer:
f.read()
Question 11.
State True or False:
The finally block will execute as soon as the exception occurs.
Answer:
False
Question 12.
What will be the output of the following Python code?
V = 25 def Fun (Ch): V=50 print (V, end=Ch) V *= 2 print (V, end=Ch) print (V, end=“*”) Fun (“!”) print (V)
(a) 25*50!100!25
(b) 50*100!100!100
(c) 25*50!100!100
(d) Error
Answer:
(a) 25*50!100!25
Question 13.
Which clause with the COUNT() function counts only the unique values in an attribute?
Answer:
DISTINCT
Question 14.
What will be the output of the following query:
Select avg(price) from product where pname like "%ke";
(a) Display maximum price of product whose name has “ke”
(b) Display average price of all products.
(c) Display average price of all products whose name ends with “ke”
(d) None of the above.
Answer:
(c) Display average price of all products whose name ends with “ke”
Question 15.
The _____________ keyword sorts the records in ascending order by default.
(a) LIKE
(b) UPDATE
(c) ORDER
(d) ORDER BY
Answer:
(d) ORDER BY
Question 16.
Which of the following is a category of SQL commands?
(a) DDL
(b) TCL
(c) DML
(d) All of these
Answer:
(d) All of these
Question 17.
Identify the first network which was based on TCP/IP protocol.
(a) Arpanet
(b) Hub
(c) Ethernet Card
(d) Router
Answer:
(a) Arpanet
Question 18.
The network device that amplifies the signals is:
(a) Gateway
(b) Repeater
(c) Modem
(d) Ethernet
Answer:
(b) Repeater
Question 19.
The switching technique that requires a fixed path to be established before communication starts is _____________
Answer:
Circuit Switching
Directions (Q. 20 and 21) are Assertion (A) and Reason (R) based questions. Mark the correct choice as
(a) Both A and R are true and R is a correct explanation of A.
(b) Both A and R are true but R is not a correct explanation of A.
(c) A is true and R is false.
(d) A is false and R is true.
Question 20.
Assertion (A): To use the randint() function, the random module needs to be included in the program.
Reason (R): Some functions are present in modules and to use them the respective module needs to be imported.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Question 21.
Assertion (A): The having clause of SQL can work only with Group by.
Reason (R): The having clause is used to filter groups formed with Group by clause.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Section B
(7 × 2 = 14)
Question 22.
Which string built-in methods are used in following conditions?
(i) Returns the length of the string.
(ii) Removes all leading whitespace in string.
Answer:
(i) len()
(ii) Istrip()
Question 23.
Give two examples of:
(a) Membership operators
(b) Identity operators
Answer:
(a) in, not in
(b) is, is not
Question 24.
Given a list Lst=[56,12,34,67,80,90]
(I) (a) Write a statement to insert 44 before 67.
Or
(b) Write a statement to display and remove the last element.
(II) (a) Write a statement to display sum of all the elements of the list.
Or
(b) Write a statement to display the last 4 elements using slicing technique.
Answer:
(I) (a) Lst.insert(3,44)
Or
(b) Lst.pop()
(II) (a) Sum(Lst) Or (b) print (Lst [2: ])
Question 25.
Which of the following can be the possible output of the code given below:
import random VALUES=[10, 20, 30, 40, 50, 60, 70, 80] BEGIN=random.randint(1, 3) LAST=random.randint(BEGIN,4) for I in range(BEGIN,LAST+1): print(VALUES[I],"-", )
(a) 30 – 40 – 50 –
(b) 10 – 20 – 30 – 40 –
(c) 30 – 40 – 50 – 60 –
(d) 30 – 40 – 50 – 60 – 70 –
Answer:
(a) 30-40-50-
Question 26.
(a) Give one point of difference between an equi-join and a natural join.
(b) What is cross join?
Answer:
(a) In equi join the common field is repeated. Whereas in natural join the common field is shown only once.
(b) A cross join or Cartesian product is a kind of join where there is no joining condition and each row of one table is joined with all the rows of the other table.
Question 27.
(I) (a) Differentiate between an attribute and a tuple with an example.
Or
(b) Consider the following table with their fields
EMPLOYEE (E_C0DE, E_NAME, DESIG, SALARY. DOJ)
List the names, salary, PF, HRA, DA of all the employees in the EMPLOYEE table. HRA is 25% of salary and DA is 10% of salary. PF is 5% of salary. The result should be in descending order of salary.
(II) (a) What are foreign keys? Write its properties.
Or
(b) How many primary keys can be defined in a table? How many foreign keys can be defined in a table?
Answer:
(I) (a) The columns of a table are referred to as attributes. It is also known as a field which is reserved for a specific piece of data. The rows of a table are referred to as tuples.
e.g.
Or
(b) SELECT E_Name, SALARY, SALARY *0.25 AS HRA, SALARY*0.10 AS DA, SALARY*0.05 AS PF FROM EMPLOYEE ORDER BY SALARY DESC:
(II) (a) Foreign key A nonkey column of a table that is the primary key in another table and links the two tables is a Foreign key. It can carry duplicate values.
(b) A table can have a single primary key and multiple foreign keys.
Question 28.
(i) Expand the following:
PAN, SMTP
(ii) Name the term defined by the given below statement.
“A group of computers connected by a link”.
(i) Name the protocol that defines how messages are formatted and transmitted.
(ii) Give one major disadvantage of Bluetooth.
Answer:
(i) PAN: Personal Area Network
SMTP: Simple Mail Transfer Protocol
(ii) A computer network is defined as a group of computers connected by a link.
Or
(i) HTTP
(ii) Only short-range communication is possible using Bluetooth.
Section C
(3 × 3 = 9)
Question 29.
Write a function Del() to delete the 4th word from a text file school.txt.
Or
Write a function countmy() in Python to read the text file “Data.txt” and count the number of times “my” occurs in the file.
For example, If the file contents are:
My first book was Me and My Family.
It gave me a chance to be known to the world.
The output of the function should be
No. of times “my” occur: 2
Answer:
def Del (): # Open the file in read mode with open('school.txt'. 'r') as f: lines = f.readlines() # Remove the 4th line (index 3) if len(lines) >= 4: del lines[3] # Open the file in write mode and save the changes with open ('school.txt'. 'w') as f: f.writelines(lines) # Call the function to execute it Del () Or def countmy(): # Open the file in read mode with open("Data.txt", "r") as f: content = f.read() # Initialize count count = 0 # Split the content into words words = content.split() # Count occurrences of "my" for word in words: if word.lower() == "my": # Use lower() to handle case-insensitive comparison count += 1 #Print the result print("No. of times 'my' occur:", count) # Call the function to execute it countmy()
Question 30.
(A) You have a stack named NumStack that storesevennumbers. The stack is implemented using a list.
Write the following user-defined functions in Python to perform the specified operations on the stack NumStack:
(I) push_num(NumStack, new_num): This function takes the stack NumStack and a new number as arguments and pushes the new number onto the stack only if it is even
(II) pop_num(NumStack): This function pops the topmost number from the stack and returns it. If the stack is already empty, the function should display “Underflow”.
(III) peep(NumStack): 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 a Python program to input as many names and push them to a stack palstack[] using the function pushnames(), only if the name input is a palindrome.
Answer:
(A) (I) defpush_num(NumStack, new_num) if new_num%2==0: NumStack.append(new_num) (II) defpop_num(NumStack): if not NumStack: print ("Underflow") else: return(NumStack.pop()) (III) def peep (NumStack): if not NumStack: print("None") else: print(NumStack[-1]) Or (B) palstack=[] defpushnames(n): pal stack.append(n) ans='y' while ans=='y': n=input("Enter a name:") if n==n[:: -1]: pushnames(n) ans=input("Add more(y/n)")
Question 31.
Consider the table APPLICANTS.
Write statements to
(a) Increase FEE of “M” (Male) applicants by 2000.
(h) Display details of “F” (Female) applicants in descending order of FEE.
(c) Change width of column FEE to 20.
Or
(a) Remove the column C_ID.
(b) Display name and joining year of female applicants
(c) Display average fee of all applicants
Answer:
(a) UPDATE APPLICANTS SET FEE=FEE+2000 WHERE GENDER = “M”: (b) SELECT * FROM APPLICANTS WHERE GENDER = “F” ORDER BY FEE DESC: (c) ALTER TABLE /APPLICANTS MODIFY FEE INTEGER (20): Or (a) ALTER TABLE APPLICANTS DROP C_ID: (b) Select Name. Joinyear from applicants where gender="F"; (c) Select Avg(Fee) from Applicants:
Section D
(4 × 4 = 16)
Question 32.
(A) (i) When is the else block executed in exceptions?
(ii) Write the names of any two common exceptions.
Or
(B) (i) Differentiate try and except blocks in exception handling.
(ii) Write a code in Python with a try block and two except blocks.
Answer:
(A) (i) The else block code executes in exception handling if no exception occurs.
(ii) IndexError – Raised when index of a sequence is out of range.
ArithmeticError – Occurs when numeric calculations fail.
Or
(B) (i) try block carries the code that is expected to raise an exception. The except block carries the code which will handle the exception if it occurs.
(ii) try: Lst=[10, 20, 30, 40, 0] print(Lst[0]/Lst[1]) print(Lst[0]/Lst[-1]) except ArithmeticError: print("Arithmetic error occurred") exceptNameError: print(”Identifier not found")
Question 33.
Riya is a student in class 12. Her teacher assigned a work to Riya to create a CSV file named Record.csv, to store the details of books available in the department. The structure of Record.csv is:
[‘BookID’, ‘AuthorName ’, Price]
For maintaining all records of books, Riya wants to write the following user-defined functions:
Insert() Enter the details of books as book id, author name, and price and add these details to the CSV file Record.csv
Total () Display the total number of books present in the record of the CSV file
As a Python expert, help her to achieve this task.
Answer:
import csv def Insert(): f1 = open("Record.csv", 'w', newline = "\n") w1 = csv.writer(f1, delimiter = "\t") w1.writerow(['BookID'.'AuthorName', 'Price']) while True: op = int(input("Enter 1 to add and 0 to exit")) if(op == 1): BookID = int(input ("Enter Book ID: ")) AuthorName = input ("Enter Author Name: ") Price = float(input ("Enter Price of book: ")) w1.writerow([BookID, AuthorName, Price]) elif op == 0: break f1.close() def Total(): f = open("Record.csv" , "r") d = csv.reader(f) next(d) #to skip header row r = 0 for row in d: r = r+1 print("Number of records are ", r) f.close() Insert () Total ()
Question 34.
Anindita is in charge of maintaining records of employees and their departments in her organization. The manager wants to view certain data as per his requirement. Help him to extract the following information.
(i) To display the average salary of all employees, department-wise.
(ii) To display the name and respective department name of each employee whose salary is more than 5000.
(iii) To display the names of employees whose salary is not known, in alphabetical order.
(iv) (A) To display DEPTID from the table EMPLOYEE without repetition.
Or
(B) To display sum of salaries of all the employees.
Answer:
(i) Select avg (salary) from employee group by deptid: (ii) Select name, deptname from employee, department where employee, deptid=department.deptid and salary>5000; (iii) Select name from employee where salary is null order by name: (iv) (A) Select distinct deptid from employee: Or (B) Select Sum(Salary) from Employee:
Question 35.
Write the code to create a table Product in the database Inventory with the following fields.
Note the following to establish the connection between Python and MySQL:
Host: localhost
Username: system
Password: hello
Database: Inventory
Answer:
import mysql.connector mycon = mysql.connector.connect(host = “localhost”, user= “system”, passwd = “hello”, database = “Inventory”) cur = mycon.cursor () db = cur.execute (“CREATE TABLE Production (PID varchar (5) Primary key, PName char (30), Price float, Rank varchar(2))”) cursor.close() mycon.close()
Section E
(2 × 5 = 10)
Question 36.
Mr. John is a developer at St. Xavier’s College and is assigned to develop a program to accept data of students and add them to a csv file.
He is also supposed to perform reading operations on the csv file to retrieve data of students of a particular city.
Help him to write a program using the following functions:
inputStud() To input details of as many students and add them to a csv file “college.csv” without removing the previous records. The file stores the records in the following structure.
SrNo Studname City Percentage
readCollege() To open the file “college.csv” and display records whose city is “Kolkata”.
Answer:
import csv def inputStud(): with open(“college.csv”,"a") as f: dt=csv.writer(f) while True: sno= int(input("Enter Serial No:")) stud_name = input("Enter student name:") city = input("Enter city:") perc = int(input("Enter percentage:")) dt.writerow([sno, stud_name, city, perc]) print( "Record has been added.") print("Want to add more record?Type YES!!!") ch = input() ch = ch.upper() if ch=="YES": print("*************************") else: break def readCollege(): with open(“college.csv”, 'r', ) as file: reader = csv.reader(file) for row in reader: if row[2]==“Kolkata”: print(row) file.close() inputStud() readCollege()
Question 37.
Sony corporation has set up its 4 offices in the city of Srinagar, with its offices X, Z, Y, U.
Branch to Branch distance is given below:
Number of computers in each of the offices is as follows:
(i) Suggest a suitable cable layout of the connectivity of the offices.
(ii) Suggest placement of server in the network with suitable reason.
(iii) Suggest placement of the following devices in the network:
(a) Switch/Hub
(b) Repeater
(iv) Suggest a suitable topology for connecting the computers in each building.
(v) (A) Write any one advantage of the topology suggested.
Or
(B) Write any one disadvantage of the topology suggested.
Answer:
(i)
(ii) Building Z, as it has the largest number of computers.
(iii) (a) Switch/Hub to be placed in all the offices.
(b) Repeater to be placed between Z-U.
(iv) Star topology.
(v) (A) Fault detection and isolation is easy.
Or
(B) Costly to set up and maintain.