In this article, I am going to discuss Term 1 Sample paper 2022-23 Computer Science Class 12 with a new pattern. You can download a few question papers for the same. So let’s begin!
Topics Covered
Sample paper 2022-23 Computer Science Class 12
CBSE has released a circular dated 20.05.2022 wide circular no. 57 for assessment and evaluation practices of the board for session 2022-23.
The Board is initiating further corresponding changes in the Examination and Assessment practices for the year 2022-23 to align assessment to Competency-Based Education. Therefore, in the forthcoming sessions, a greater number of Competency Based Questions or questions that assess the application of concepts in real-life/ unfamiliar situations will be part of the question paper.
New changes for Sample paper 2022-23 Computer Science Class 12 XII (2022-23)
The changes for Sample paper 2022-23 Computer Science Class 12 XII (2022-23) internal year-end/Board Examination are as detailed:
Theory Exam
| Board examination (Theory) | Existing (2021-22) | Modified (Annual Scheme 2022-23) |
| Composition | Term I – Multiple Choice Question including case-based and assertion reasoning type MCQs – 100% ( 20% questions competency-based) Term II – Case-based/ Situation based, Open-ended- short answer/long answer (20% questions competency-based) | Competency Based Questions would be minimum 30%. These can be in the form of Multiple Choice Questions, Case based Questions, Source-based Integrated Questions or any other types. Objective Type Questions will be 20% Remaining 50% Short Answer/Long Answer Questions (as per existing pattern) |
Internal Assessment
There is no change in internal assessment and it is the same as prescribed in the CBSE curriculum document released via board vide circular no. 50/2022 on 28th April 2022.
Instructions for paper
Here are the general instructions for Sample paper 2022-23 Computer Science Class 12 as given below:
- This question paper contains five sections, sections A to E.
- All questions are compulsory.
- Section A has 18 questions carrying 01 mark each.
- Section B has 07 Very Short Answer type questions carrying 02 marks each.
- Section C has 05 Short Answer type questions carrying 03 marks each.
- Section D has 03 Long Answer type questions carrying 05 marks each.
- Section E has 02 questions carrying 04 marks each. One internal choice is given in Q35 against part c only.
- All programming questions are to be answered using Python Language only.
Now download the Sample paper 2022-23 Computer Science Class 12 linked in the next section.
Download the Sample paper
Chapter-wise Weightage and Blue Print
| Sr. No. | Topic | 1 M | 2 M | 3 M | 5 M | 4 M | Total | Marks |
| 1 | Revision Tour | 7 | 2* | 1 | – | – | 10* | 12 |
| 2 | Function | 1 | 2* | – | 2* | – | 5* | 8 |
| 3 | File Handling | 3 | – | 2* | 2* | 1 | 8* | 15 |
| 4 | Stack | – | – | 2* | – | – | 2* | 3 |
| 5 | Networking | 5 | 3* | – | 1 | – | 9* | 14 |
| 6 | DBMS | 1 | 3* | 2 | – | 1 | 7* | 12 |
| 7 | Python Connectivity | 1 | – | – | 2* | – | 3* | 6 |
| Total Questions | 18* | 10* | 7* | 7* | 2 | 44* | 70 | |
| OR | – | 4 | 2 | 3 | – | 9 | ||
| To be attempted | 18 | 7 | 5 | 3 | 2 | 35 | ||
| Marks | 18 | 14 | 15 | 15 | 8 | 70 |
Question Wise Explanation
[1] State True or False: “Variable declaration is implicit in Python.”
Ans. True
Explanation:In implicite variable declaration, the data type of variable is automatically determined at comile time by the compiler from the value used to initialize the varibale. Sometimes implicite varibale declaration done by some other code in the background.
[2] Which of the following is an invalid datatype in Python?
- (a) Set
- (b) None
- (c)Integer
- (d)Real
Ans. d) Real
Explanation:
a) Set is one of the built-in data types in Python that stores the collection of data
b) None is a special literal of python that is used to define null or no value in python
c) Integer is a one of the premitive data type of python that allows assign numeric values such as zero, positvie or negative number without fractional part
d) Real is not a data type it is just a part of complex number type
[3] Given the following dictionaries:
dict_exam={"Exam":"AISSCE", "Year":2023}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?
- a. dict_exam.update(dict_result)
- b. dict_exam + dict_result
- c. dict_exam.add(dict_result)
- d. dict_exam.merge(dict_result)
Ans.: a. dict_exam.update(dict_result)
Explanation:
a) The dict.update() method will dict2 to dict1. In this questions dict1 is dict_exam and dict2 to dict_result
b) The + is used to concat or addition for two numeric value. Dictionary is key-value pair object which does not support + directly.
c) There is no attribute named add supported for dictionary
d) There is no attribute baned merge supported for dictionary
[4] Consider the given expression:
not True and False or True
Which of the following will be the correct output if the given expression is evaluated?
- (a) True
- (b) False
- (c) NONE
- (d) NULL
Ans. a) True
Explanation:
a) Python evaluation from left to right not True – False then False and False returns False and Finally False or True Returns True.
[5] Select the correct output of the code:
a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)
- (a) Year . 0. at All the best
- (b) Year 0. at All the best
- (c) Year . 022. at All the best
- (d) Year . 0. at all the best
Ans.: a. Year . 0. at All the best
Explanation: The split() method splits the words from given character so it returns the list [‘Year ‘, ‘0’, ”, ‘ at All the best’]. Then a[0] – Year , a[1] – 0 and a[3] at All the best. These words will be concated using . Hence option a is the correct answer.
[6] Which of the following mode in file opening statement results or generates an error if the file does not exist?
- (a) a+
- (b) r+
- (c) w+
- (d) None of the above
Ans. (b) r+
Explanation:
a) a+ mode is used for appending and reading the data
b) r+ mode is used for write and read data but does not create a file
c) w+ mode creates a file if doesn’t exist
[7] Fill in the blank:
___________________________ command is used to remove primary key from the table in SQL.
- (a) update
- (b) remove
- (c) alter
- (d) drop
Ans. c) alter
Explanation:
a) Update command is DML command and used to update the values in the table
b) remove command is not application in SQL
c) alter command is DDL command which is used to add, drop and modify the structure of the table
d) drop command is a DDL command
[8] Which of the following commands will delete the table from MYSQL database?
- (a) DELETE TABLE
- (b) DROP TABLE
- (c) REMOVE TABLE
- (d) ALTER TABLE
Ans. b) Drop Table
Explanation:
a) Delete Table: It is not command, delete is used to delete the rows from a table
b) Drop Table: It is DDL command and used to delete the table
c) Remove Table: Remove Table is not a command of SQL
d) Alter Table: Command is used to modify the table structure
[9] Which of the following statement(s) would give an error after executing the following code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3
(b) Statement 4
(c) Statement 5
(d) Statement 4 and 5
Ans. b) Statement 4
Explanation:
Statement 3 – Assigns Thank you to variable S
Statement 4 – @ can’t be assigned to first letter of string in s
Statement 5 – It concats two joined both words
Statement 4 and 5 – 4 raise error but 5 will execute
[10] Fill in the blank:
_______________ is a non-key attribute, whose values are derived from the primary key of some other table.
- (a) Primary Key
- (b) Foreign Key
- (c) Candidate Key
- (d) Alternate Key
Ans. b) Foreign Key
Explanation:
a) Primary key is used to identify the unique records in table
b) Foregin key is a refereneced column of the another table’s primary key
c) Candidate key is a column which can be a primary key in a table
d) Alternate Key is a colum which are candiate key other than primary key
[11] The correct syntax of seek() is:
- (a) file_object.seek(offset [, reference_point])
- (b) seek(offset [, reference_point])
- (c) seek(offset, file_object)
- (d) seek.file_object(offset)
Ans. a) file_object.seek(offset [,reference_point])
[12] Fill in the blank:
The SELECT statement when combined with _______________ clause, returns records without repetition.
- (a) DESCRIBE
- (b) UNIQUE
- (c) DISTINCT
- (d) NULL
Ans. c) Distinct
Explanation:
a) Describe command is used to get the detailed strcuture of a table
b) Unique is a constraint which is used to add unique records in the table
c) Distinct key word is used to display unique records from group of rows
d) NULL is used to insert empty value in the record
[13] Fill in the blank:
__________ is a communication methodology designed to deliver both voice and multimedia communications over Internet protocol.
- (a) VoIP
- (b) SMTP
- (c) PPP
- (d)HTTP
Ans.: a) VoIP
Explaination:
All are the protocols used in the internet, SMTP, PPP and HTTP are useful for mail transfer, file transfer and document transfer whereas VoIP is used to transfer Voice Over Internet.
[14] What will the following expression be evaluated to in Python?
print(15.0 / 4 + (8 + 3.0))
- (a) 14.75
- (b)14.0
- (c) 15
- (d) 15.5
Ans. a) 14.75
Explanation:
It evaluates the expression as 8 + 3 = 11 then 15/4 = 3.75 then 11 + 3.75 = 14.75
[15] Which function is used to display the total number of records from table in a database?
- (a) sum(*)
- (b) total(*)
- (c) count(*)
- (d) return(*)
Ans.: c) count(*)
[16] To establish a connection between Python and SQL database, connect() is used. Which of the following arguments may not necessarily be given while calling connect() ?
- (a) host
- (b) database
- (c) user
- (d) password
Ans. b) database
Explanation:
For creating connection you need to establish a connection with instance of the DBMS software. Hence by username, password and host we can establish a connection and database can be created or added later also.
Q17 and 18 are ASSERTION AND REASONING 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
[17] Assertion (A):- If the arguments in function call statement match the number and order of arguments as defined in the function definition, such arguments are called positional arguments.
Reasoning (R):- During a function call, the argument list first contains default argument(s) followed by positional argument(s).
Ans.: c) A is True but R is False
During function the argument list first contains the positional arguments followed by default arguments.
[18] Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like a text file.
Reason (R): The information is organized with one record on each line and each field is separated by comma.
Ans. a) Both A and R are True and R is correct reason for A
[19] Rao has written a code to input a number and check whether it is prime or not. His code is having errors. Rewrite the correct code and underline the corrections made.
def prime():
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0:
print("Number is not prime \n")
break
else:
print("Number is prime \n’)
Ans.
Errors:
Line 2: Bracket is missing
Line 4: Eaual to missing
Line 8: Quote mismatch
[20] Write two points of difference between Circuit Switching and Packet Switching.
Ans.:
Circular switching:
1. Circuit switching is the method of switching which is used for establishing a dedicated communication path between the sender and the receiver.
2. Data is processed and transmitted at the source only.
3. It is more reliable.
4. Iin circuit swithing, the connection is established, then data is goign to be transfered and lastly the connection is released.
5. The entire path of data is known every unit.
Packet Switching:
1. Packet switching is the method of switching where no dedicated path is established from the source to the destination.
2. Data is processed and transmitted, not only at the source but at each switching station.
3. It is less reliable.
4. Packet Switching there is not steps, data trasnsfer takeplaces directly.
5. The destination address is known to data unit and the intermiediate path is decided by routers.
OR
Write two points of difference between XML and HTML.
Ans.:
XML (Extensible MarkupLangauge)
XML tags are not predefined, they are user defined
XML stores and transfers data.
Dynamic in nature
HTML (Hypertext Markup Langauge)
HTML tags are pre-defined and it is a markup language
HTML is about displaying data.
Static in nature
[21] (a) Given is a Python string declaration:
myexam="@@CBSE Examination 2022@@"
Write the output of: print(myexam[::-2])
(b) Write the output of the code given below:
my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())
Ans.:
a) @20 otnmx SC@
b) dict_items([(‘name’, ‘Aman’), (‘age’, 27), (‘address’, ‘Delhi’)])
Explanation:
a) In this statement the slicing extract data from rever of the string. It takes the jump -2 everytime.
b) The dcit_items() method an item of dictionary as specifed. In the dicrionary when subscript value is used it changes th existing data or add new if data does not exist.
[22] Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer.
Ans.: A foreign key is used to set or represent a relationship between two relations ( or tables) in a database. Its value is derived from the primary key attribute of another relation.
For example:
In the tables TRAINER and COURSE given below, TID is primary key in TRAINER table but foreign key in COURSE table.
Write a suitable example of tab;le.
[23] (a) Write the full forms of the following:
- (i) SMTP
- (ii) PPP
(b) What is the use of TELNET?
Ans.:
a)
(i) SMTP – Simple Mail Transfer Protocol
(ii) PPP – Point to Point Protocol
b)
TELNET is used to access a remote computer / network.
Explanation:
Telnet is one of the protocols that it used to virtually access the computer and provde a two way, text-based and collaborative communication channel. It follows a user command TCP/IP networking protocol for creating remote sessions.
[24] Predict the output of the Python code given below:
def Diff(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),'#', end=' ')
Ans. 22 # 40 # 9 # 13 #
Explanation:
The given loop is backward indexing loop which starst with 4. So it access the last element and Store that element into A and 1 element before will be stores into varibale B.
In first iteration A=32 & B = 54. So B>A hence B-A = 22 followed by character #
Second Iteration A=54 and B=14. So A>B hence A-B = 40 followed by # character
Third iteration A=14 and B=23. So B>A hence B-A = 9 followed by # character
Fourth iteration A=23 and B=10. So A>B hence A-B=12 followed by # character
So the final output will be 22 # 40 # 9 # 13 #
OR
Predict the output of the Python code given below:
tuple1 = (11, 22, 33, 44, 55 ,66)
list1 =list(tuple1)
new_list = []
for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
Ans.: (22,44,66)
Explanation:
In the begining tuple is initialized with the values 11,22,33,44,55,66.. Then in next line is converted into the list using list() function. In the next line an empty list is created. After that the list is travered and appended the iven number into the emty list created a new_list. So even number 22,44,66 will be appended to the new list and final result will be (22,44,66)
[25] Differentiate between count() and count(*) functions in SQL with appropriate example.
Ans. COUNT(*) returns the count of all rows in the table, whereas COUNT () is used with Column_Name passed as argument and counts the number of non-NULL values in a column that is given as argument.
OR
Categorize the following commands as DDL or DML:
INSERT, UPDATE, ALTER, DROP
Ans. :
DDL Commands: Alter, Drop
DML Commands: Insert, Update
[26] (a) Consider the following tables – Bank_Account and Branch:
Table: Bank_Account
| ACode | Name | Type |
| A01 | Amrita | Savings |
| A02 | Parthodas | Current |
| A03 | Miraben | Current |
Table: Branch
What will be the output of the following statement?
SELECT * FROM Bank_Account NATURAL JOIN Branch;
Ans.:

Explanation:
Natural join displays the result from two table having common columns. Here ACode is common columns
(b) Write the output of the queries (i) to (iv) based on the table, TECH_COURSE given below:
Table : Tech_Course
| CID | CNAME | FEES | STARTDATE | TID |
| C201 | Animation and FX | 12000 | 2002-07-02 | 101 |
| C202 | CADD | 15000 | 2021-11-15 | NULL |
| C203 | DCA | 10000 | 2020-11-01 | 102 |
| C204 | DDTP | 9000 | 2021-09-15 | 104 |
| C205 | Mobile application and development | 18000 | 2022-11-01 | 101 |
| C206 | Digital Marketing | 16000 | 2022-07-25 | 103 |
(i) SELECT DISTINCT TID FROM TECH_COURSE;
(ii) SELECT TID, COUNT(*), MIN(FEES) FROM TECH_COURSE GROUP BY TID HAVING COUNT(TID)>1;
(iii) SELECT CNAME FROM TECH_COURSE WHERE FEES>15000 ORDER BY CNAME;
(iv) SELECT AVG(FEES) FROM TECH_COURSE WHERE FEES BETWEEN 15000 AND 17000;
Ans.:
(i)

Ans.: In this query distinct key word is used with select clause. This eliminates the duplicate records and display only unique records.
(ii)

Ans.: In this query recods are counted minimum fees displayed in groups based on TID. TID 101 having the more than one rows. hence it is displayed.
(iii)

Ans.: This query display course name from the table whose fees more than 15000 in ascending order.
(iv)
15500.00
Ans. The avg() function calculation averge of the specified data.
[27] Write a method COUNTLINES() in Python to read lines from text file ‘TESTFILE.TXT’ and display the lines which are not starting with any vowel.
Example:
If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
A marked difference will come in our country.
The COUNTLINES() function should display the output as:
The number of lines not starting with any vowel – 1
Ans.:
def COUNTLINES() :
file = open ('TESTFILE.TXT', 'r')
lines = file.readlines()
count=0
for w in lines :
if (w[0]).lower() not in 'aeoiu'
count = count + 1
print ("The number of lines not starting with any vowel: ", count)
file.close()
COUNTLINES()
Ans. The function requires to open the file in reading mode. The lines object stroes the number lines present in the texstfile.txt. To count the number of lines not starting with any vowel the lines object traversed and count variable is used to increase the the line if the conditon evalauates to true. Finally the output line is written using print and lastly the file is closed using close.
OR
Write a function ETCount() in Python, which should read each character of a text file “TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T individually (including small cases e and t too).
Example:
If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount() function should display the output as:
E or e: 6
T or t : 9
Ans.:
def ETCount() :
file = open ('TESTFILE.TXT', 'r')
lines = file.readlines()
countE=0
countT=0
for w in lines :
for ch in w:
if ch in 'Ee':
countE = countE + 1
if ch in 'Tt':
countT=countT + 1
print ("The number of E or e : ", countE)
print ("The number of T or t : ", countT)
file.close()
[28] (a) Write the outputs of the SQL queries (i) to (iv) based on the relations between Teacher and Placement given below:
Table : Teacher

Table: Placement
| P_ID | Department | Place |
| 1 | History | Ahmedabad |
| 2 | Mathematoics | Jaipur |
| 3 | Computer Sc | Nagpur |
(i) SELECT Department, avg(salary) FROM Teacher GROUP BY Department;
(ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher;
(iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department = P.Department AND Salary>20000;
(iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender =’F’ AND T.Department=P.Department;
Ans.:

Ans.: This query display the average salary department wise.
(ii)

Ans.: This query display the maximum and minimym dates from the relation.
(iii)

Ans.: This query displays the result from two tables and with a conidition.
(iv)

(b) Write the command to view all tables in a database.
Ans. show tables
[29] Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the function. The function returns another list named ‘indexList’ that stores the indices of all Non-Zero Elements of L.
For example:
If L contains [12,4,0,11,0,56]
The indexList will have – [0,1,3,5]
Ans.:
def INDEX_LIST(L):
indexList=[]
for i in range(len(L)):
if L[i]!=0:
indexList.append(i)
return indexList
[30] A list contains following record of a customer:
[Customer_name, Phone_number, City]
Write the following user defined functions to perform given operations on the stack named ‘status’:
(i) Push_element() – To Push an object containing name and Phone number of customers who live in Goa to the stack
(ii) Pop_element() – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack.
For example:
If the lists of customer details are:
[“Gurdas”, “99999999999”,”Goa”]
[“Julee”, “8888888888”,”Mumbai”] [“Murugan”,”77777777777”,”Cochin”]
[“Ashmit”, “1010101010”,”Goa”]
The stack should contain
[“Ashmit”,”1010101010”]
[“Gurdas”,”9999999999”]
The output should be:
[“Ashmit”,”1010101010”]
[“Gurdas”,”9999999999”]
Stack Empty
Ans.:
status=[]
def Push_element(cust):
if cust[2]=="Goa":
L1=[cust[0],cust[1]]
status.append(L1)
def Pop_element ():
num=len(status)
while len(status)!=0:
dele=status.pop()
print(dele)
num=num-1
else:
print("Stack Empty")
OR
Write a function in Python, Push(SItem) where , SItem is a dictionary containing the details of stationary items– {Sname:price}.
The function should push the names of those items in the stack who have price greater than 75. Also display the count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Ditem={“Pen”:106,”Pencil”:59,”Notebook”:80,”Eraser”:25}
The stack should contain
Notebook
Pen
The output should be:
The count of elements in the stack is 2
Ans.:
stackItem=[]
def Push(SItem):
count=0
for k in SItem:
if (SItem[k]>=75):
stackItem.append(k)
count=count+1
print("The count of elements in the stack is : ", count)
[31] MakeInIndia Corporation, an Uttarakhand based IT training company, is planning to set up training centres in various cities in next 2 years. Their first campus is coming up in Kashipur district. At Kashipur campus, they are planning to have 3 different blocks for App development, Web designing and Movie editing. Each block has number of computers, which are required to be connected in a network for communication, data and resource sharing. As a network consultant of this company, you have to suggest the best network related solutions for them for issues/problems raised in question nos. (i) to (v), keeping in mind the distances between various blocks/locations and other given parameters.

Distance between various blocks/locations:
| Block | Distance |
| App development to web designing | 28 m |
| App development to Movie Editing | 55 m |
| Web Designing to Movie Editing | 32 m |
| Kashipur Campus to Mussoorie Campus | 232 km |
No. of computer:
| Block | Number of computers |
| App Development | 75 |
| Web Designing | 50 |
| Movie Editing | 80 |
(i) Suggest the most appropriate block/location to house the SERVER in the Kashipur campus (out of the 3 blocks) to get the best and effective connectivity. Justify your answer.
(ii) Suggest a device/software to be installed in the Kashipur Campus to take care of data security.
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to economically connect various blocks within the Kashipur Campus.
(iv) Suggest the placement of the following devices with appropriate reasons:
a. Switch / Hub
b. Repeater
(v) Suggest a protocol that shall be needed to provide Video Conferencing solution between Kashipur Campus and Mussoorie Campus.
Ans.:
Ans.
(i) Movie editing block is the most appropriate to house the server as it has the maximum number of computers.
(ii) firewall
(iii) Ethernet Cable
(iv) Switch/hub will be placed in all blocks to have connectivity within the block. Repeater is not required between the blocks as the distances are less than 100 mts.
(v) VoIP
Cable Layout for iii:

[32] (a) Write the output of the code given below:
p=5
def sum(q,r=2):
global p
p=r+q**2
print(p, end= '#')
a=10
b=5
sum(a,b)
sum(r=5,q=1)
Ans.: 105#6#
Explanation: Initially p is 5, a is 10, and b is 5. Now in first sum(a,b) function p becomes 5+10**2 = 5 + 100 = 105. In second sum(r=5,q=1) p becomes 5 + 1**2 = 5 + 1 =6. Hence the output is 105#6#.
(b) The code given below inserts the following record in the table Student:
RollNo – integer
Name – string
Clas – integer
Marks – integer
- Note the following to establish connectivity between Python and MYSQL:
- Username is root
- Password is tiger
- The table exists in a MYSQL database named school.
- The details (RollNo, Name, Clas and Marks) are to be accepted from the user.
Write the following missing statements to complete the code:
- Statement 1 – to form the cursor object
- Statement 2 – to execute the command that inserts the record in the table Student.
- Statement 3- to add the record permanently in the database
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root", password="tiger", database="school")
mycursor=_____ #Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
clas=int(input("Enter class :: "))
marks=int(input("Enter Marks :: "))
querry="insert into student values({},'{}',{},{})".format(rno,name,clas,marks)
__________ #Statement 2
__________ # Statement 3
print("Data Added successfully")
Ans.:
Statement 1:
con1.cursor()
Statement 2:
mycursor.execute(querry)
Statement 3:
con1.commit()
OR
(a) Predict the output of the code given below:
s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'): m = m +s[i].upper() elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)
Ans.: sELCcME&Cc
(b) The code given below reads the following record from the table named student and displays only those records who have marks greater than 75:
- RollNo – integer
- Name – string
- Clas – integer
- Marks – integer
- Note the following to establish connectivity between Python and MYSQL:
- Username is root
- Password is tiger
- The table exists in a MYSQL database named school.
- Write the following missing statements to complete the code:
- Statement 1 – to form the cursor object
- Statement 2 – to execute the query that extracts records of those students whose marks are greater than 75.
- Statement 3- to read the complete result of the query (records whose marks are greater than 75) into the object named data, from the table student in the database.
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger", database="school")
mycursor=___ #Statement 1
print("Students with marks greater than 75 are : ")
_____________ #Statement 2
data=______ #Statement 3
for i in data:
print(i)
print()
Ans.:
Statement 1:
con1.cursor()
Statement 2:
mycursor.execute(“select * from student where Marks>75”)
Statement 3:
mycursor.fetchall()
[33] What is the advantage of using a csv file for permanent storage? Write a Program in Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements as empid, name and mobile to store employee id, employee name and employee salary respectively.
(ii) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’.
Ans.:Advantage of a csv file:
- It is human readable – can be opened in Excel and Notepad applications
- It is just like text file
Program:
import csv
def ADD():
fout=open("record.csv","a",newline="\n")
wr=csv.writer(fout)
empid=int(input("Enter Employee id :: "))
name=input("Enter name :: ")
mobile=int(input("Enter mobile number :: "))
lst=[empid,name,mobile] ---------1/2 mark
wr.writerow(lst) ---------1/2 mark
fout.close()
def COUNTR():
fin=open("record.csv","r",newline="\n")
data=csv.reader(fin)
d=list(data)
print(len(d))
fin.close()
ADD()
COUNTR()
OR
Give any one point of difference between a binary file and a csv file.
Write a Program in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record consists of a list with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.
(ii) search()- To display the records of the furniture whose price is more than 10000.
Ans.:
Difference between binary file and csv file: (Any one difference may be given)
Binary file:
- Extension is .dat
- Not human readable
- Stores data in the form of 0s and 1s
CSV file
- Extension is .csv
- Human readable
- Stores data like a text file
import csv
def add():
fout=open("furdata.csv","a",newline='\n')
wr=csv.writer(fout)
fid=int(input("Enter Furniture Id :: "))
fname=input("Enter Furniture name :: ")
fprice=int(input("Enter price :: "))
FD=[fid,fname,fprice]
wr.writerow(FD)
fout.close()
def search():
fin=open("furdata.csv","r",newline='\n')
data=csv.reader(fin)
found=False
print("The Details are")
for i in data:
if int(i[2])>10000:
found=True
print(i[0],i[1],i[2])
if found==False:
print("Record not found")
fin.close()
add()
print("Now displaying")
search()
[34] Navdeep creates a table RESULT with a set of records to maintain the marks secured by students in Sem 1, Sem2, Sem3 and their division. After creation of the table, he has entered data of 7 students in the table.

Based on the data given above answer the following questions:
(i) Identify the most appropriate column, which can be considered as Primary key.
Ans.: ROLL_NO
(ii) If two columns are added and 2 rows are deleted from the table result, what will be the new degree and cardinality of the above table?
Ans.: Degree – 8, Cardinality 5
(iii) Write the statements to:
a. Insert the following record into the table
Roll No- 108, Name- Aadit, Sem1- 470, Sem2-444, Sem3-475, Div – I.
b. Increase the SEM2 marks of the students by 3% whose name begins with ‘N’.
Ans.:
a. INSERT INTO RESULT VALUES (108, ‘Aadit’, 470, 444, 475, ‘I’);
b. UPDATE RESULT SET SEM2=SEM2+ (SEM2*0.03) WHERE SNAME LIKE “N%”;
OR
(Option for part iii only)
(iii) Write the statements to:
a. Delete the record of students securing IV division.
b. Add a column REMARKS in the table with datatype as varchar with 50 characters
a. DELETE FROM RESULT WHERE DIV=’IV’;
b. ALTER TABLE RESULT ADD (REMARKS VARCHAR(50));
[35] Aman is a Python programmer. He has written a code and created a binary file record.dat with employeeid, ename and salary. The file contains 10 records.
He now has to update a record based on the employee id entered by the user and update the salary. The updated record is then to be written in the file temp.dat. The records which are not to be updated also have to be written to the file temp.dat. If the employee id is not found, an appropriate message should to be displayed.
As a Python expert, help him to complete the following code based on the requirement given above:
import #Statement 1
def update_data():
rec={}
fin=open(“record.dat”,”rb”)
fout=open(“__“) #Statement 2
found=False
eid=int(input(“Enter employee id to update their salary :: “))
while True:
try:
rec=__ #Statement 3
if rec[“Employee id”]==eid:
found=True
rec[“Salary”]=int(input(“Enter new salary :: “))
pickle.__ #Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print(“The salary of employee id “,eid,” has been updated.”)
else:
print(“No employee with such id is not found”)
fin.close()
fout.close()
(i) Which module should be imported in the program? (Statement 1)
(ii) Write the correct statement required to open a temporary file named temp.dat. (Statement 2)
(iii) Which statement should Aman fill in Statement 3 to read the data from the binary file, record.dat and in Statement 4 to write the updated data in the file, temp.dat?
Ans.:
(i) pickle
(ii) fout=open(‘temp.dat’, ‘wb’)
(iii) Statement 3: pickle.load(fin)
Statement 4: pickle.dump(rec,fout)
Watch this video for more understanding:
If you are looking for a questions chapter wise follow these links:
Objective-type questions have a vital role in making question papers now. So if you are looking for MCQs for the same follow this link:
Computer Science MCQ Questions
This blueprint for a computer science class 12 is prepared by us as per the new pattern to help the community to make a question paper for half yearly exam or term 1 exam. Here we will try to provide you few sample papers for the same.
More Sample Papers for Half yearly/ Mid Term/PT 2/Term 1 Exam
| S.No | Sample Paper & Marking Scheme | Answer key | Youtube Video |
| 1 | SQP 1 | SQP 1 Answer Key | Watch video |
| (As per CBSE Sample Paper Strictly) | |||
| 2 | SQP 2 | SQP 2 Answer Key | Watch Video |
More Sample paper 2022-23 Computer Science Class 12 Pre-board/Prelim/Practice
| S.No | Sample Paper (Source) | Answer key | Youtube Video |
| 1 | Sample Paper 1 – Courtesy | View/Download | Watch Now |
| 2 | Sample Paper 2 | View/Download | Watch Now |
| 3 | Sample Paper 3 (KV Jammu PDF) | View/Download | Wtach Now |
| 4 | Sample Paper 4 (Koimbatore Sahodaya Schools Complex) | View/Download | Coming Soon… |
| 5 | Sample Paper 5 (Koimbatore Sahodaya Schools Complex) | View/Download | Coming Soon |
More Sample Papers for Computer Science Class 12
| S.No | Download PDF |
| 1 | KV All Regions |
| 2 | Jammu Region |
| 3 | Kerala Sahodaya |
| 4 | S. S. Mota Singh Sr. Sec. Model School |
I hope this will help you to make a plan and question paper according to the syllabus. Your views/opinions/suggestions are highly appreciable by our community, hence feel free to express them in the comment section.
Share this with more people around you and help them. Let us make an effort to help the community by joining our hands together.
Thank you for reading this article Sample paper 2022-23 Computer Science Class 12.
question paper 1(corrections)
q-24 output–> 34@53@ or [4,7]
[13,24]
q-26 output of (iv)
Thank you for notice
sir, There is a question in which there is information is incomplete.
sample paper — 5
Question no — 24
Will see and update
sir, In sample paper –2 Answer Key question no. 33 > (b) > (ii) .The solution is given by f=csvwriter() as wrong.
It should be csv.writer(f)