Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 4 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 4 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 [1]
“Lists and dictionaries are mutable.”
Answer:
True
Question 2.
In complex number a + ib, b represents as [1]
(a) real part
(b) imaginary part
(c) special part
(d) None of these
Answer:
(b) imaginary part
Question 3.
Given an object obj1 = (10, 20, 30, 40, 50, 60, 70, 80, 90). What will be the output of print(obj1[3 : 7 : 2])? [1]
(a) (40, 50, 60, 70, 80)
(b) (40, 50, 60, 70)
(c) (40, 50, 60)
(d) (40, 60)
Answer:
(d) (40,60)
Question 4.
Which of the following is the correct output for the execution of the following Python statement? [1]
print (5 + 3 ** 2/2)
(a) 32
(b) 8.0
(c) 9.5
(d) 32.0
Answer:
(c) 9.5
Question 5.
Identify the output from the following options. [1]
sub = "PYTHON" for i in sub print (i, ' ', end = " ")
(a) P Y T H O N
(b) P
Y
T
H
O
N
(c) None
(d) P,Y,T,H,O,N
Answer:
(a) P Y T H O N
Question 6.
Which path does not start with a leading forward slash ? [1]
(a) Relative
(b) Absolute
(c) Both (a) and (b)
(d) None of these
Answer:
(a) Relative
Question 7.
IP address are converted into [1]
(a) a binary string
(b) alphanumeric string
(c) a hierarchy of domain name
(d) a hexadecimal
Answer:
(c) a hierarchy of domain name
Question 8.
Which of the following SQL commands displays the structure of a table? [1]
(a) ALTER
(b) STRUCTURE
(c) DESCRIBE
(d) SHOW DATA
Answer:
(c) DESCRIBE
Question 9.
Observe the following tuples and choose the correct option [1]
t1=(4, 7, 8, 9) t2=(0, 4, 3) >>>t=t1+t2 >>>print(t)
(a) (4, 7, 8, 9, 0, 4, 3)
(b) (4, 7, 8, 9, 4, 7, 8, 9)
(c) (4, 7, 8, 9)
(d) None of these
Answer:
(a) (4, 7, 8, 9, 0, 4, 3)
Question 10.
Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which of the following option can be used to read all the remaining lines? [1]
(a) myfile.read(n-3)
(b) myfile.read(n)
(c) myfile.readline()
(d) myfile.readlines()
Answer:
(d) myfile.readlines()
Question 11.
Fill in the blank : ……… is an attribute that makes a link between two tables to fetch corresponding data. [1]
(a) Primary key
(b) Secondary key
(c) Foreign key
(d) Composite key
Answer:
(c) Foreign key
Question 12.
Which of the following function returns the total number of values? [1]
(a) MAX
(b) MIN
(c) COUNT
(d) SUM
Answer:
(c) COUNT
Question 13.
State whether the following statement is True or False. The clause to get the unique values from a field of a table is DISTINCT. [1]
Answer:
True
Question 14.
Which of the following is the correct output for the following execution ? [1]
print(print(“Biscope”))
(a) Biscope
(b) None
(c) Biscope
None
(d) Error
Answer:
Question 15.
Fill in the blank : …….. is a protocol used for uploading and downloading of files in a network. [1]
Answer:
FTP
Question 16.
What is default value of host? [1]
(a) host
(b) localhost
(c) globalhost
(d) None of these
Answer:
(b) localhost
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) Built-in functions are predefined in the system and can be directly used in any program. [1]
Reason (R) id() and type() are built-in functions in Python.
(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:
(b) Both A and R are true but R is not the correct explanation for A.
Question 18.
Assertion (A) The CSV files are like TEXT files and are comma separated value files. [1]
Reason (R) The data stored in CSV files are separated by comma by default. Although the delimiter can be changed.
(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.
(i) Expand the following terms: [1+1=2]
MAN, FTP
(ii) What was the role of ARPANET in the computer network? [2]
Or
(i) Name two switching techniques used to transfer data between two terminals (computers).
(ii) How can a Word document be sent alongwith an E-mail? [2]
Answer:
(i) MAN Metropolitan Area Network FTP File Transfer Protocol
(ii) ARPANET (Advanced Research Projects Agency Network) goal was to connect computers at different universities and US defense. ARPANET started with a handful of computers but it expanded rapidly.
Or
(i) Switching techniques used to transfer data between two terminals are [2]
(a) Circuit switching
(b) Packet switching
(ii) By attaching the Word file with an E-mail.
Question 20.
Riya was asked to accept a list of even numbers, but she did not put the relevant condition while accepting the list of numbers. She wrote a user-defined function oddtoeven (L) that accepts the list L as an argument and converts all the odd numbers into even by multiplying them by 2. [2]
def oddtoeven (L) : for i in range (sized(L)): if (L[i]% 2! == 0) L [i] = L [i] ** 2 print (L)
There are some errors in the code. Rewrite the correct code.
Answer:
def oddtoeven (L): for i in range (len(L)): if (L[i]% 2! =0) : L [i]= L [i] * 2 print (L)
Question 21.
Observe the code and write the output. [2]
'arihant publication'.count(‘hant', 0, 10) "arihant".isupper()
Or
Observe the code and write the output.
dic = {} dic [(1, 2, 4)] = 8 dic [(4, 2, 1)] = 10 dic [(1, 2)] = 24 sum = 0 for i in die : sum = sum + dic [i] print (sum)
Answer:
1 Or 42
False
Question 22.
Write about the terms degree and cardinality of a table. [2]
Or
Write a query on the Salespeople table, whose output will exclude all salespeople with a rating > = 100, unless they are located in Delhi. [2]
Answer:
Degree It refers to the number of columns/attributes in a table.
Cardinality It refers to the number of rows/records in a table.
A table Employee stores records of 10 employees in the following structure
Eno Ename Dept Salary
The degree of the table is 4.
The cardinality of the table is 10.
Or
SELECT * FROM Salespeople WHERE NOT rating > = 100 OR city = ‘Delhi’;
Question 23.
Observe the following program and answer the question that follow; [2]
import random x = 3 N = random.randint (1, x) for i in range (N): print (i, #, i + 1)
What is the maximum and minimum number of times the loop will execute?
Answer:
Maximum number = 3,
Minimum number = 1 ’
Question 24.
Find the output of following code. [2]
dic = (“Nitin” : (21, “NUT”), “Ankit” : (15, “NIIT")} } print(‘‘The original dictionary : ”, str(dic)) result = [(key, i, j) for key, (i, j) in dic.items( )] print(“The list after conversion : ”, str(result))
Or
What output will be generate when the following Python code is executed? [2]
def ChangeList ( ): l = [ ] l1 = [ ] l2 = [ ] for i in range (1, 10): l.append (i) for i in range (10, 1, -2): l1.append (i) for i in range (len (l1)): l2.append (l1 [i] + l[i]) l2.append (len (l) - len (l1) print (l2) ChangeList ( )
Answer:
The original dictionary : {‘Ankit’ : (15, ‘NIIT’), ‘Nitin’ : (21, ‘NIIT’)}
The list after conversion : [(‘Ankit’, 15, ‘NIIT’), (‘Nitin’, 21, ‘NIIT’)]
Or
Output
[11, 10, 9, 8, 7, 4]
Question 25.
What is the output of the given code? [2]
(i) int(math.pow(2, 5))
(ii) print(math.pow(2, 5))
Answer:
(i) 32
(ii) 32.0
Section – C
Question 26.
Write the output for SQL queries (i) to (iii), which are based on the table ITEMS. [1 × 3 = 3]
TABLE: ITEMS
(i) SELECT MAX(Price), MIN(Price) FROM ITEMS:
(ii) SELECT Price * Qty AS AMOUNT FROM ITEMS WHERE Code=1004;
(iii) SELECT DISTINCT TCode FROM ITEMS;
Answer:
Question 27.
Write a function countEU() in Python, which should read each character of a text file IMP.TXT should count and display occurrence of alphabets E and U (including small cases e and u too). [3]
e.g. If the file content is as follows :
Pinaky has gone to his friend’s house.
His friend’s name is Ravya. Her house is 12 km from Pinaky’s house.
The countEU() function should display the output as
E : 8; U : 3
Or
Write a Python program to find the longest word in file “status.txt”. If contents of status.txt are Welcome to your one-step solutions for all your study, practice and assessment need for various competitive and recruitment examinations and school segment. We have been working tirelessly for over a decade to make sure that you have best in class study resources because you deserve SUCCESS AND NOTHING LESS…
Output should be :
Longest word : examinations [3]
Answer:
def countEU( ): f=open(‘TMP.TXT”) e=0 u=0 while True: l=f.readline( ) if not l: break for i in l: if (i==‘E’ or i==‘e’): e=e+1 elif(i==‘U’ or i==‘u’): u=u+1 print(“E :”,e) print(“U :”,u) f.closed ( )
Or
def Longest( ): f=open("status.txt”) words=f.read( ).split( ) max_len=len(max(words, key=len)) for word in words: if(len(word)==max_len): print(“Longest word:”,word)
Question 28.
Consider the following tables GARMENT and FABRIC. Write SQL commands for the statements (i)to(iii). [1 × 3 = 3]
TABLE: GARMENT
TABLE:FABRIC
(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENTS, which have READYDATE in between 08-DEC-07 and 16-JUN-08 (inclusive of both the dates).
(iii) To display the average PRICE of all the GARMENTS. Which are made up of FABRIC with FCODE as F03.
Answer:
(i) SELECT GCODE, DESCRIPTION FROM GARMENT ORDER BY GCODE DESC;
(ii) SELECT*FROM GARMENT WHERE READYDATE BETWEEN ‘08-DEC-07’ AND ’16-JUN-08’ ;
(iii) SELECT AVG(PRICE) FROM GARMENT WHERE FCODE = ‘F03’; –
Question 29.
Write the definition of a function Reverse (x) in Python, to display the elements in reverse order such that each displayed element is the twice of the original element (element *2) of the List x in the following manner: [3]
Example :
If List x contains 7 integers is as follows:
x[0] | X[1] | X[2] | X[3] | X[4] | X[5] | X[6] |
4 | 8 | 7 | 5 | 6 | 2 | 10 |
After executing the function, the array content should be displayed as follows:
20 | 4 | 12 | 10 | 14 | 16 | 8 |
Answer:
def Reverse (x): for i in range (len (x) - 1, -1, -1) : print (x[i] *2)
Question 30.
Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a program, with separate user defined functions to perform the following operations
Push the keys (name of the student) of the dictionary into a stack, where the corresponding value (marks) is greater than 75. [3]
Pop and display the content of the stack.
For example If the sample content of the dictionary is as follows
R={“OM”:76, “JAI”:45, “BOB”:89, “ALI”:65, ‘’ANU”:90, “TOM”:82}
The output from the program should be TOM ANU BOB OM
Answer:
R={"OM": 76, "JAI":45, "BOB": 89. "ALI":65, "ANU”:90, "TOM": 82} def PUSH(S, N): S.append(N) def POP(S): if S!=[]: return S.pop( ) else: return None ST=[ ] for k in R: if R[k]>=75: PUSH(ST, k) while True: if ST!=[ ]: print(POP(ST),end=" ") else: break
Section – D
Question 31.
Consider the table MOVIEDETAILS given below [1 × 4 = 4]
Table : MOVIEDETAILS
Write statements to :
(a) Delete the records whose language is “English”.
(b) Add a new record : “M050”, “Palki”, “Hindi”, 5,”Amazon Prime”.
(c) Add a new column “DAYS” of type integer.
(d) Remove the column “RATING”.
Answer:
(a) DELETE FROM MOVIEDETAILS WHERE LANGUAGE=”ENGLISH”;
(b) INSERT INTO MOVIEDETAILS VALUES (“M050”, “Palki”,”Hindi”, 5,“Amazon Prime”);
(c) ALTER TABLE MOVIEDETAILS ADD DAYS INTEGER;
(d) ALTER TABLE MOVIEDETAILS DROP RATING;
Question 32.
Write a program using following functions : [4]
getInventory() Write code to accept as many inventory records and store them to the csv file Inventory.csv storing records of inventory as per following structure
PCode Invname Price Reorder
Display() To display the detail that store in Inventory.csv
Answer:
from csv import writer def getlnventory( ): with open("Inventory.csv ","a",newline="\n") as f : dt = writer (f) while True: pcode= int(input("Enter Inventory code:")) inv_name = inputC'Enter inventory name:") price = eval (input("Enter Price: ”)) rol = int(input("Enter reorder level:")) dt.writerow([pcode,inv_name,price, rol]) print("Record has been added.") printC'Want to add more record?Type YES!!!") ch = input() ch = ch.upper() if ch=="YES": print ("****************") else: break def Display( ): f = open("Inventory.csv","r") dt = reader(f) data = list(dt) f.close( ) for i in data: for j in i: print(’\t',j, end=" ") print( ) getInventory( ) Display( )
Section – E
Question 33.
Red Pandas Infosystems has its 4 blocks of buildings. The number of computers and distances among them is given below : [1 × 5 = 5]
Building | Number of Computers |
HR | 15 |
ADMIN | 100 |
SYSTEM | 25 |
PERS | 30 |
Building | Distance |
HR-Admin | 10m |
HR-System | 50m |
HR-Pers | 750m |
Admin-System | 300m |
Admin-Pers | 20m |
System-Pers | 250m |
Answer the following questions with respect to the above :
(i) Suggest a suitable cable layout for the network.
(ii) Suggest the best place to house the server of the network.
(iii) Which topology should be used to connect computers in each building?
(iv) What kind of network will be formed here? (LAN/MAN/WAN)
(v) Write one advantage of the topology suggested by you.
Answer:
(i) The cable layout is given below :
(ii) ADMIN building, as it has the maximum number of computers.
(iii) Star topology, as it is the topology offering best facilities.
(iv) LAN – Local Area Network
(v) Fault detection is easy.
Question 34.
(i) What is CSV file? [2 + 3 = 5]
(ii) Write a program using two functions :
addCustomer() To write Customer code, Customer name and Amt in file “cust.csv”.
The details of the customers are as follows :
[‘CustCode’, ‘CustName’, ‘Amount’]
[‘001’, ‘Nihir’, ‘8000’]
[‘104′, ’Akshay’, ‘5000’]
readCustomer() To read the details of the customers and display them.
Or
(i) When do we use CSV file? [5]
(ii) A Binary file, STATUS.DAT has the following structure:
[BNO:[BNAME, BTYPE])
Where,
BNO – Book Number
BNAME – Book Name
BTYPE is Book Type
Write a user-defined function, selectType(btype), that accepts btype as parameter and displays all the records from the binary file STATUS.DAT, that have the value of Book Type as btype.
Answer:
(i) CSV (Comma Separated Values) is a file format for data storage which looks like a text file.
(ii) import csv
def addCustomer(): f1 = open(’cust.csv', 'w', newline = "\n”) w1 = csv.writer(f1, delimiter = ”;") w1.writerow(['CustCode', 'CustName', 'Amount']) w1.writerow(['001', 'Nihir', '8000']) w1.writerow(['104', 'Akshay', '5000']) f1.close( ) readCustomer( ): with open("cust.csv”, 'r',“\n”) as file1: reader = csv. reader(file1, delimiter = ";") for row in reader: print(row) file1.close( ) addCustomer( ) readCustomer()
Or
(i) We can use CSV file when
- Data has a strict tabular structure.
- To transfer large data between programs.
- To import and export data.
(ii) import pickle
def selectType(btype): f1 = open("STATUS.DAT", "rb”) try: while True: data = pickle.load (f1) if data [2] == btype: print("Book number: ",data[0]) printC'Book Name : ", data[1]) print("Book type: ", data [2]) except EOFError: f1.close( )
Question 35.
(i) Differentiate between DROP and DELETE commands of SQL. [1 + 4 = 5]
(ii) Consider the table Student whose fields are
Write the Python code to update grade to ‘A’ for all these students who are getting more than 8 as points.
The table structure is as follows:
Scode : integer
Name : varchar
Age : integer
Strcde : integer
Points : integer
Grade : varchar
Note the following to establish the connection between Python and MySQL:
Host: localhost
Username : Admin
Password : Admin@123
The table exists in MySQL database as: Student
Or
(i) Identify any two DML commands from the following and also explain.
ALTER, INSERT, UPDATE, DROP, CREATE
(ii) Consider the table MobileStock with following fields
M_Id, M_Name, M_Qty, M_Supplier
Write tile Python code to fetch all records with fields M_Id, M_Name and MSupplier from database Mobile.
Consider:
host: localhost
UserName : root
Password : system
Database : Mobile
Answer:
(i) The DROP command removes the entire table with its structure and records. DELETE command is used to delete records of a table.
(ii)
import mysql.connector as mydb con = mydb.connect (host = “localhost”, user = “Admin”, passwd = "Admin@123”, database = "system”) cursor = con.cursor ( ) sql = "UPDATE Student SET Grade = ‘A’ WHERE Points > 8” try : cursor, execute (sql) con.commit ( ) except : con.rollback ( ) con.close ( )
Or
(i) INSERT, UPDATE
The INSERT command adds a record to a table.
The UPDATE command is used to change record(s) of a table.
(ii)
import mysql .connector as mydb mycon=mydb.connect (host = “localhost”, user = “root”, passwd = “system”, database = “Mobile”) cursor = mycon.cursor () sql = “SELECT M_Id, M_Name, M_Supplier FROM MobileStock” try: cursor.execute (sql) display = cursor, fetchall( ) for i in display: print (i) except: mycon.rollback( ) mycon.close()