Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 2 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 2 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]
Digits are one of the parts of the Python character set.
Answer:
True
Question 2.
Which of the following are the most obvious kind of constants? [1]
(a) Keywords
(b) Literals
(c) Variables
(d) Identifiers
Answer:
(b) Literals
Question 3.
Which of the following operator cannot be used with string data type? [1]
(a) +
(b) in
(c) *
(d) /
Answer:
(d)/
Question 4.
What is the output of the following code? [1]
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 5.
Given : s=”ComputerExam”. What will be the output of print(s[2]+s[8]+s[1:5])? [1]
(a) mEOMUU
(b) mEompu
(c) mEomPU
(d) MEompu
Answer:
(b) mEompu
Question 6.
Which of the following types of files will need the pickle module for working on it? [1]
(a) Binary’ files
(b) Text files
(c) CSV files
(d) All of these
Answer:
(a) Binary files
Question 7.
What will be the output of the following Python code? [1]
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 8.
Which of the following is a category of SQL commands? [1]
(a) DDL
(b) TCL
(c) DML
(d) All of these
Answer:
(d) All of these
Question 9.
In the following code, which lines will give error? (Assume the lines are numbered starting from 1.) [1]
mul=3
value=10
for i in range (1, 6, 1): .
if (value % mul = 0):
print (value * multiply)
else
print (value + multiply)
(a) 4, 5
(b) 4,5,6
(c) 4,5,6,7
(d) No errors
Answer:
(c) 4,5,6,7
Question 10.
Fill in the blank [1]
There can be ……….. foreign keys in a relation.
Answer:
multiple
Question 11.
Which of the following functions will read lines of a text file as list elements? [1]
(a) read()
(b) get()
(c) readline()
(d) readlines()
Answer:
(d) readlines()
Question 12.
Fill in the blank
The ………. clause with the COUNT0 function counts only the unique values in an attribute. [1]
(a) UNIQUE
(b) HAVING
(c) DISTINCT
(d) LIKE
Answer:
(c) DISTINCT
Question 13.
State whether the following statement is True or False.
Telnet is a protocol used for remote login.
Answer:
True
Question 14.
Which of the following will be the output of the statement given below? [1]
print([12,34,56,78,90] . pop( ))
(a) 78
(b) 90
(c) 12
(d) 12,34,56,78,90
Answer:
(b) 90
Question 15.
GSM is a standard set developed by the [1]
(a) European Telecommunications Standards Institute
(b) Telecommunication Institute
(c) Quality of Service
(d) None of the above
Answer:
(a) European Telecommunications Standards Institute [1]
Question 16.
Identify the first network which was based on TCP/IP protocol. [1]
(a) arpanet
(b) Hub
(c) Ethernet Card
(d) Router
Answer:
(a) arpanet
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) To use the randint() function, the random module needs to be included in the program. [1]
Reason (R) Some functions are present in modules and to use them the respective module needs to be imported.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of 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 of A.
Question 18.
Assertion (A) The contents of a Binary file are not directly interpretable. [1]
Reason (R) Modes in which binary files can be opened are suffixed with ‘b’ like : rb/wb etc.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of 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 of A.
Section – B
Question 19.
(i) Expand the following [1+1=2]
PAN, SMTP
(ii) Name the term defined by given below statement.
“ A group of computers connected to each other by a link”.
Answer:
Or
(i) Name the protocol 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) Computer network is defined as a group of computers connected to each other by a link.
Or
(i) HTTP
(ii) Only short range communication is possible using bluetooth.
Question 20.
Find the error(s). [2]
Answer:
Error 1 L2 = L1 + 2 because + operator cannot add list with other type as number or string.
Error 2 L = L1.pop(7) parentheses puts index value instead of element. In the given list, maximum index value is 3 and 7 is out of index range.
Question 21.
Observe the code and write the output: [2]
t = ‘HELLO’
t1 = tuple(t)
print(t1)
print(t1[1:3])
Or Predict the output of the following code:
x = (1, 2, 3)
y = (3, 4)
t = x + y
print(t)
t[2] = 4
print(t)
Answer:
Question 22.
Differentiate between an attribute and a tuple with an example. [2]
Or
Consider the following table with their fields
EMPLOYEE (E_CODE, 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.
Answer:
The columns of a table are referred to as attributes. It is also known as field which is reserved for a specific piece of data. The rows of a table are referred to as tuples, e.g.
Or
SELECT E_Name, SALARY, SALARY * 0.25 AS HRA, SALARY*010 AS DA, SALARY*0.05 AS PF FROM EMPLOYEE ORDER BY SALARY DESC;
Question 23
Differentiate between identifier and keyword. [2]
Answer:
Differences between identifier and keyword are
Identifier | Keyword |
Identifier consists any combination of letters, numbers and underscores. | Keyword must consist only letters. |
It allows both uppercase and lowercase. | It allows only lowercase except True, False and None. |
e.g. x, sum_5, _mul etc. | e.g. finally, continue, yield etc. |
Question 24.
Identify the output of the following Python code. [2]
D={1 : “One", 2 : “Two”, 3 : "Three”} L = [ ] for K, V in D.items( ): if V[0] = = “T”: L.append (K) print(L)
Or
Identify the output of the following Python statement. [2]
lst1 = [10, 15, 20, 25, 30] lst1.insert(3, 4) lst1.insert(2, 3) print (lst1[-5])
Answer:
Output [2, 3]
Or
Output 3
Question 25.
Write the short note on [2]
(i) isupper()
(ii) join()
Answer:
(i) isupper() It returns True if string has atleast one case character and all case characters are in uppercase and False otherwise.
Syntax string.isupper()
(ii) join() It returns a string in which the elements of sequence have been joined by string separator.
Syntax string.join(iterable)
Section – C
Question 26.
Write the output for SQL queries (i) to (iii), which are based on the table CARDEN. [1 × 3 = 3]
(i) SELECT COUNT(DISTINCT Make) FROM CARDEN;
(ii) SELECT COUNT(*) Make FROM CARDEN;
(iii) SELECT CarName FROM CARDEN WHERE Capacity = 4;
Answer:
Question 27.
Write a function Del() to delete the 4th word from a text file school.txt. [3]
Or
Write a function county() 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 chance to be known to the world.
The output of the function should be
No. of times “my” occur : 2
Answer:
def Del ( ):
with open(‘school.txt’ ,‘r’ ) as f:
l = f. readlines()
f.close()
print(l)
f = del l[3]
print(l)
f = open (‘school.txt’, ‘w’)
f.writelines(l)
f.closed( )
Or
def countmy():
f=open(“Data.txt”,“r”)
count=0
x=f.read()
word=x.split()
for i in word:
if(i==“my”):
count=count+1
print(“No. of times my occur:”, count)
countmy()
Question 28.
Write the output of the queries (i) to (iii) based on the table FURNITURE given below. [1 × 3 = 3]
Table : FURNITURE
(i) SELECT SUM(DISCOUNT) FROM FURNITURE WHERE COST > 15000 ;
(ii) SELECT MAX( DATEOFPURCHASE) FROM FURNITURE ;
(iii) SELECT * FROM FURNITURE WHERE DISCOUNT>5 AND FID LIKE ”T%”;
Answer:
Question 29.
Write a user-defined function findname (name), where name is an argument in Python to delete phone number from a dictionary phonebook on the basis of the name, where name is the key. [3]
Answer:
def findname (name): if phonebook.has_key (): del phonebook [name] else: print (“Name not found”) print (“Phonebook Information”) print (“Name”, \t, “Phone no") for i in phonebook.keys ( ): print (i, \t, phonebook [i])
Question 30.
Write Push (contents) and Pop (contents) methods in Python to add numbers and remove numbers considering that to act as Push and Pop operations of stack. [3]
Answer:
def Push (contents) : if(len(stack) >= limit) : print(“Stack Overflow!”) else : stack . append (contents) print (“Stack after Push”, stack) def Pop ( ) : if (len (stack) <= 0 ) : print(“Stack Underflow!”) return 0 else : return stack. Pop( )
Section – D
Question 31.
Consider the table APPLICANTS. [1 × 4 = 4]
TABLE: APPLICANTS
Write statements to
(a) Increase FEE of “M” (Male) applicants by 2000.
(b) Display details of “F” (Female) applicants in descending order of FEE.
(c) Change width of column FEE to 20.
(d) Remove the column C_ID.
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);
(d) ALTER TABLE APPLICANTS DROP C_ID;
Question 32.
Riya is a student of 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 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 detail of books as book id, author name and price and add this details to CSV file Record.csv
Total () Display the total number of books present in record of CSV file
As a Python expert, help her to achieve this task. [4]
Answer:
import csv def Insert( ): f1 = open("Record.csv", 'w', newline = "\n") w1 = csv.writer(f1, delimiter = "\t") w1.writerowCr([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(f) #to skip header row r = 0 for row in d: r = r+1 print("Number of records are " , r) f.close( ) Insert( ) Total ( )
Section – E
Question 33.
Sony corporation has set up its 4 offices in the city of Srinagar, with its offices X, Z, Y, U: [1 × 5 = 5]
(i) Suggest a suitable cable layout of connectivity of the offices.
(ii) Suggest placement of server in the network with suitable reason.
(iii) Suggest placement of following devices in the network:
(a) Switch/Hub
(b) Repeater
(iv) Suggest a suitable topology for connecting the computers in each building.
(v) Write any one advantage 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) Fault detection and isolation is easy.
Question 34.
(a) Describe the following terms
(i) Domain
(ii) DB2
(b) Write the code to create a table Product in database Inventory with following fields
Fields | Datatype |
PID | varchar(5) |
PName | char(30) |
Price | float |
Rank | varchar(2) |
Note the following to establish the connection between Python and MySQL:
Host: localhost
Username : system
Password : hello
Database : Inventory [5]
Or
(a) Identify commands/functions for the following action.
To add a new column to a table.
(b) Which data will get added in table Company by following code?
import mysql.connector con = mysql.connector.connect ( host = "localhost”, user = "system”, passwd = "hello”, database = "connect”) cur = con.cursor ( ) sql = "insert into Company (Name, Dept, Salary) values (%s, %s, %s)” val = ("ABC”, “DBA”, 35000) cur.execute (sql, val) con.commit ( )
Consider :
host: localhost
UserName : system
Password : hello
Database : connect [5]
Solution:
(a) (i) Domain is a set of possible values for an attribute. A domain is said to be atomic, if elements of the domain are considered as individual units. .
(ii) DB2 is a Relational Database Management System (RDBMS), fully featured, high performance database capable of handling large quantities of data and concurrently serving many users. :
(b)
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)))” mycon.closet )
Or
(a) ALTER TABLE < table_name>ADD column_name datatype;
(b) “ABC”, “DBA”, 35000
Question 35.
(i) Does Python create a file itself if the file doesn’t exist in the memory? Illustrate your answer with an example. [2+3=5]
(ii) Write a program using following functions:
inputStud() To input details of as many students and add them to a csv file “college.csv” ‘
without removing the previous records.
SrNo Studname City Percentage
readCollege() To open the file “college.csv” and display records whose city is “Kolkata”
Or
(i) Write a statement to create a data.txt file with the following text.
” Python file handling is very interesting”
(ii) Write a Python code using two functions as follows :
removeRow() To remove a record from the college file “College.csv” having following structure.
SrNo Studname City Percentage
getCollege() To read the records of the college file “College.csv” and display names of students whose names start with a lowercase vowel. [5]
Answer:
(i) Python will create a file automatically when the open function is used with write mode.
Example:
f=open(“data.txt”,”w") f.write(“Hello\nHow are you?”) f.close( )
(ii)
import csv def inputStud( ) : with open(“college.csv","a") as f: dt = 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( )
Or
(i)
f = open ("data.txt". "w") f. write ("Python file handling is very interesting") f.close( )
(ii)
import csv def removeRow( ): record = list( ) sname= input("PIease enter a student name to delete:") with open('College.csv', 'r') as f: data = csv.reader(f) for row in data: record.append(row) for field in row: if field == sname: record.remove(row) with open('Col lege.csv', 'w') as f: writer = csv.writer(f) writer.writerows(record) def getCollege( ) : with open("College.csv", ’r') as file: reader = csv.reader(file) for row in reader: if row[1][0] in ‘aeiou': print(row) file.close( ) removeRow( ) getCollege( )