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 hrs Max.
Marks: 70
Instructions
1. Please check this question paper contains 35 questions.
2. The paper is divided into 5 Sections A, B, C, D and E.
3. Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
4. Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
5. Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
6. Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
7. Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
8. All programming questions are to be answered using Python Language only.
Section – A
Question 1.
State True or False.
“Variable declaration is implicit in Python.” [1]
Answer:
True
Question 2.
Which of the following is an invalid datatype in Python? [1]
(a) Set
(b) None
(c) Integer
(d) Real
Answer:
(d) Real
Question 3.
Given the following dictionaries [1]
dict_exam={“Exam”:”AISSCE”, “Year”:2023}
dict_result=(“Total500, “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)
Answer:
(a) dict_exam.update(dict_result)
Question 4.
Consider the given expression: not True and False or True
Which of the following will be correct output, if the given expression is evaluated? [1]
(a) True
(b) False
(c) NONE
(d) NULL
Answer:
(a) True
Question 5.
Select the correct output of the code: [1]
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
Answer:
(a) ‘Year . 0. at All the best’.
Question 6.
Which of the following mode in file opening statement results or generates an error, if the file does not exist? [1]
(a) a+
(b) r+
(c) w+
(d) None of these
Answer:
(b) r+
Question 7.
Fill in the blank:
………. command is used to remove primary key from the table in SQL. [1]
(a) UPDATE
(b) REMOVE
(c) ALTER
(d) DROP
Answer:
(c) ALTER
Question 8.
Raghav is trying to write an object objl = (1, 2, 3, 4, 5) on a binary file “test.bin”. Consider the following code written by him. [1]
import pickle obj1 = (1, 2, 3, 4, 5) myfile = open (''test.bin", ‘wb’) pickle. _____ #Statement 1 myfile.close ( )
Identify the missing code in Statement 1.
(a) dump(myfile . obj1)
(b) dump (obj1 . my file)
(c) write(obj1 . myfile)
(d) load(myfile.obj1)
Answer:
(b) dump (obj1 . my file)
Question 9.
Which of the following statement(s) would give an error after executing the following code? [1]
(a) Statement 3
(b) Statement 4
(c) Statement 5
(d) Statement 4 and 5
Answer:
(b) Statement 4
Question 10.
Which of the following statements are true about URL? [1]
(a) URL means Uniform Resource Locator
(b) You can enter URL into address bar
(c) An example of URL is [email protected]
(d) Both (a) and (b)
Answer:
(d) Both (a) and (b)
Question 11.
The correct syntax of seek() is [1]
(a) file_object.seek(offset [, reference_point])
(b) seek(offset [, reference_point])
(c) seek(offset, file_object)
(d) seek.file_object(offset)
Answer:
(a) file_object.seek(offset [, reference point])
Question 12.
State whether the following statement is True or False.
The SELECT statement when combined with NULL clause, returns records without repetition. [1]
Answer:
False
Question 13.
Fill in the blank: [1]
……… is a communication methodology designed to deliver both voice and multimedia communications over Internet protocol.
Answer:
VoIP
Question 14.
What will the following expression be evaluated to in Python? [1]
print(15.0 / 4 + (8 + 3.0))
(a) 14.75
(b) 14.0
(c) 15
(d) 15.5
Answer:
(a) 14.75
Question 15.
Which function is used to display the total number of records from table in a database? [1]
(a) SUM(*)
(b) T0TAL(*)
(c) COUNT(*)
(d) RETURNS (*)
Answer:
(c) COUNT(*)
Question 16.
Which transmission media is commonly used in transporting multi-channel television signals in cities? [1]
(a) Optical Fibre
(b) Co-axial cable
(c) Ethernet cable
(d) None of these
Answer:
(b) Co-axial cable
Directions In the question numbers 17 and 18, a statement of Assertion (A) is followed by a statement of Reason (R). Choose the correct option.
Question 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. [1]
Reason (R) During a function call, the argument list first contains default argument(s) followed by positional argument(s).
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true but R is not the correct explanation for A.
(c) A is true but R is false.
(d) A is false but R is true.
Answer:
(c) A is true but R is false.
Question 18.
Assertion (A) CSV (Comma Separated Values) is a file format for data storage which looks like a text file. [1]
Reason (R) The information is organised with one record on each line and each field is separated by comma.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true but R is not the correct explanation for A.
(c) A is true but R is false.
(d) A is false but R is true.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Section – B
Question 19.
Rao has written a code to input a number and check whether it is prime number or not. His code is having errors. Rewrite the correct code and underline the corrections made. [2]
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’) Answer: def prime() : n=int(input(”Enter number to check :“)) for i in range (2, // 2) : if n%i==0: print(”Number is not prime \n”) break else: print(’Number is prime \n”)
Question 20.
Define any two operations on data structure. [2]
Answer:
Two operations on data structure are as follows
- Insertion It means addition of a new data element in a data structure.
- Searching It involves searching for the specific data element in a data structure.
Question 21.
Given is a Python string declaration: [2]
myexam=“@@CBSE Examination 2022@@”
Write the output of : print (myexam [: : – 2])
Answer:
@20 otnmx SC@
Or
Write the output of the code given below: [2]
my_dict = {"name” : “Aman”, “age” : 26} my_dict [ ‘age ’ ] = 27 my_dict[‘address’] = “Delhi” print(my_dict.items()) Answer: di.ct_items([(’name’, ‘Aman’), (‘age’. 27), (‘address’, ‘Delhi’)]) The age is updated to 27 and a new key address’ has been added with value ‘Delhi’.
Question 22.
Explain the use of ‘Foreign Key’ in a Relational Database Management System. [2]
Answer:
A foreign key is a linking field between two tables and brings corresponding or matching values from two tables.
Or
Consider the following table with their fields Student (RollNo, Name, Marks 1, Marks2, Address) List the name, total of all the students in the Student table. The total is find to sum up of Mark1 and Mark2. [2]
Answer:
SELECT Name, (Mark1 + Mark2) AS “Total” FROM Student;
Question 23.
(a) Write the full forms of the following: ; [1 + 1 = 2]
(i) SMTP
(ii) PPP
Answer:
(i) SMTP Simple Mail Transfer Protocol
(ii) PPP Point to Point Protocol
(b) What is the use of TELNET?
Answer:
TELNET is an application protocol to login to a remote server. Such logins can be used to get access to remote data and software resources.
Or
(a) Which media are especially used for remote locations which are difficult to reach with wired infrastructure?
(b) Name any two components required for networking. [2]
Answer:
(a) Satellites
(b) Switch/hub and repeaters
Question 24.
Predict the output of the Python code given below: [2]
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 = ‘ ’)
Answer:
22 # 40 # 9 # 13 #
Or
Predict the output of the Python code given below: [2]
tuplel = (11, 22, 33, 44, 55 ,66) listl = list(tuple1) new_list = [ ] for i in listl: if i%2==0: new_list.append(i) new_tuple = tuple(new_list) print(new_tuple)
Answer:
(22, 44, 66)
Question 25.
Rewrite the following Python program after removing all the syntactical errors (if any), underlining each correction. [2]
def checkval: x = input ("Enter a number”) if x % 2 = 0: print (x, "is even") else if x<0: print(x, "should be positive") else; print (x, "is odd") Answer: def checkval ( ): x input (“Enter a number”) if x % 2 == 0 : print (x, "is even") elif x < 0 : print (x, "should be positive") else : print (x, "is odd")
Section – C
Question 26.
Write the output of the queries (i) to (iii) based on the table, TECH_COURSE given below: [1 × 3 = 3]
Table: TECH.COURSE
(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;
Answer:
Question 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. [3]
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
Answer:
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()
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). [3]
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
Answer:
def ETCount( ): f=open( “TESTFILE.TXT”) e=0 t=0 while True: l=f.readline( ) if not l: break for i in l: if ( i==’E’ or i==’e’): e=e+1 e l i f(i==’T’ or i==’t’): t=t+1 print(”E :“, e) print(”T :“, t) f.close( )
Question 28.
Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and Placement given below: [1 × 3 = 3]
Table: Teacher
Table: Placement
(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;
Answer:
Question 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. [3]
For example:
If L contains [12, 4, 0, 11, 0, 56]
The indexList will have – [0, 1, 3, 5]
Answer:
def INDEX_LIST (L) : indexList=[] for a in range(0, Len(L)): if not L[a]==0: indexlist.append(a) return indexList
Question 30.
A list contains following record of a customer: [3]
[Customer_name, Phone_number, City]
Write the following user-defined functions to perform given operations on the stack named ‘status’:
Push_element() To Push an object containing name and Phone number of customers who live in Goa to the stack
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
Answer:
def Push_element(custLst): for rec in custLst: if rec[2]==”Goa”: status. append( rec) def Pop_element(custLst): for a in range(-1, -1*len(custLst) -1, 1): print (custLst [a]) print(”Stack Empty”)
Section – D
Question 31.
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. [1 × 4 = 4]
Based on the data given above, write the statements to:
(a) Insert the following record into the table
Roll No- 108, Name- Aadit, Semi- 470, Sem2-444, Sem3-475, Div-1
(b) Increase the SEM2 marks of the students by 3% whose name begins with ‘N’.
(c) Delete the record of students securing IV division.
(d) Add a column REMARKS in the table with datatype as varchar with 50 characters.
Answer:
(a) INSERT INTO RESULT VALUES(108,” Aadit”, 470, 444, 475, ”I”) ;
(b) UPDATE RESULT SET SEM2=SEM2+ (SEM*0.03) WHERE SNAME LIKE “N%”;
(c) DELETE FROM RESULT WHERE DIV=”IV”;
(d) ALTER TABLE RESULT ADD COLUMN REMARKS VARCHAR(50);
Question 32.
Aman is a Python programmer. He has written a code and created a binary file record.dat wit\ employeeid, ename and salary. The file contains 10 records. [4]
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 write the code.
Answer:
import pickle def update_data( ) : rec={ } fin=open(”record . dat”, “rb”) fout=open(”temp.dat”, “wb”) found=False eid=int(input("Enter employee id to update their salary :: “)) while True: try : rec = pickle.load(fin) if rec[”Employee id”]= =eid: found=True rec[”Salary”]=int(input(”Enter new salary :: “)) pickle.pickle.dump(rec, fout) 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( )
Section – E
Question 33.
MakeInIndia Corporation, 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. [1 × 5 = 5]
Distance between various blocks/locations:
Number of computers
(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.
Answer:
(i) Movie Editing block, as it has the maximum number of computers.
(ii) Firewall
(iii) Optical fibre cable
Cable Layout
(iv) (a) Switch/Hub to be placed in all buildings, as all have multiple computers that need to be connected.
(b) Repeater to be placed between App Development and Movie Editing blocks as the distance between
them is larger.
(v) VoIP Voice over Internet Protocol
Question 34.
(i) Differentiate between COUNT() and COUNT(*) functions in SQL. [1 + 4 = 5]
(ii) Write a code to insert the following record in the table Student:
RollNo – integer
Name – string
Class – 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, Class and Marks) are to be accepted from the user.
Answer:
(i) 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.
(ii) import mysql . connector as. MySQL
def sql_data( ) : con1 = mysql.connect(host=”localhost”,user=”root”, password=”tiger”, database=”school”) mycursor= con1.cursor() 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) mycursor.execute (querry) con1.commit( ) print("Data Added sucessfully")
Or
(i) Categorise the following commands as DDL or DML: [5]
INSERT, UPDATE, ALTER, DROP
(ii) Write the code to read record from the table named student and displays only those records who have marks greater than 75:
RollNo – integer
Name – string
Class – 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.
Answer:
(i) DDL ALTER, DROP
DML INSERT, UPDATE
(ii) import mysql .connector as MySQL
def sql_data( ) : con1 = mysql.connect(host = “localhost”, user = “root”, password = “tiger”, database = “school”) mycursor = conl.cursor( ) print(”Students with marks greater than 75 are : “) mycursor.execute("Select*from student where marks > 75”) data = niycursor.fetchall( ) for i in data: print(i) print( )
Question 35.
(i) What is the advantage of using a CSV file for permanent storage? [2 + 3 = 5]
(ii) Write a program in Python that defines and calls the following user-defined functions:
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 sal to store employee id, employee name and employee salary, respectively.
COUNTR() To count the number of records present in the CSV file named ‘record.csv’.
Answer:
(i) It can store data values separated by comma. It provides a record type structures that can be used in database or
dataframe format.
(ii) import csv
e id=”” e name=” “ sal="" eLst= [] def ADD( ) : with open (‘record.csv’,’w’) as f: eid=input(”Enter employee ID :“) ename=input(”Enter employee name :“) sal=input(’Enter employee salary :") eLst.append(e id) eLst.append(ename) eLst.append(sal) writer=csv.writer (f) writer.writerow (eLst) f.close() def COUNTR( ): ctr=0 with open("record.csv”) as f reader=csv . reader( ) for rec in reader : print (rec) ctr+=1 print(”No. of records :“,ctr) f.close( ) def main( ): ADD( ) COUNTR ( ) main ( )
Or
(i) Give any one point of difference between a binary file and a CSV file. [5]
(ii) Write a program in Python that defines and calls the following user-defined functions: 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.
search() To display the records of the furniture whose price is more than 10000.
Answer:
(i) A binary file is stored in binary format and easy, fast for the computer to process. While, CSV file is a simple text file
storing data in text format in a record structure separating data by comma.
(ii) import csv
fid=”” fname=”" fprice=0 . 0 fLst=[ ] def add( ): with open (‘furdata.csv’,’W’) as f: fid=input(”Enter furniture ID :“) fname=input(”Enter furniture name :“) fprice=float(input(Enter furniture price :“)) fLst.append(fid) fLst.append(fname) fLst.append(f price) writer=csv.writer(f) writer.writerow (fLst) f.close( ) def search( ): try: f=open(’furdata.csv’, ‘r’) reader=csv.reader(f) for rec in reader : if float(rec[2])>10000: print(rec) f.close( ) except: print(”End of file”) def main( ): add ( ) search ( ) main ( )