Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 6 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 6 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.
Python doesn’t support nested functions.
Answer:
False
Question 2.
What will be the output for the following Python statements?
L = [10, 20, 30, 40, 50] L = L + 5 print(L)
(a) [10, 20, 30, 40, 50, 5]
(b) [15, 25, 35, 45, 55]
(c) [5, 10, 20, 30, 40, 50]
(d) Error
Answer:
(d) Error
Question 3.
Which of the following will result to True?
(a) False and not False
(b) False or not False and not True
(c) 8%9=0 and 16//2=7
(d) 12=3*4 or 7%3=1
Answer:
(d) 12=3*4 or 7%3=1
Question 4.
What will be the output of the following Python code?
print (“xyz. PQR”. capitalized)
(a) xyz. PQR
(b) XYZ. PQR
(c) Xyz. pqr
(d) Xyz. Pqr
Answer:
(d) Xyz.Pqr
Question 5.
What is the output of the following display() function call
def display(**kwargs): for i in kwargs: print(i) display(emp="Kelly", salary=9000)
(a) TypeError
(b) Kelly
9000
(c) (’emp’, ‘Kelly’)
(‘salary’, 9000)
(d) emp
salary
Answer:
(d) emp
salary
Question 6.
The following code will produce output as:
t=tuple() t = t +(‘Python’.) print (t) print (len(t)) t1=(10,20,30) print (len(t1))
(a) 1
3
(b) (‘Python’,)
1
(c) (‘Python’,’)
1
4
(d) (‘Python’,)
1
3
Answer:
(d) (‘Python’,)
1
3
Question 7.
v = 50 def Change(N): global v v, N = N, v print(v, N, sep="#",end="@") Change(20) print(v)
(a) 20#50@20
(b) 50@20#50
(c) 50#50#50
(d) 20@50#20
Answer:
(a) 20#50@20
Question 8.
The method that inserts an element at a certain index of a list is?
(a) add()
(b) insertval()
(c) insert()
(d) addElement()
Answer:
(c) insert()
Question 9.
What is the output of “ElephantFalls”[2:6].upper()?
(a) “Epnt”
(b) ‘EHTF’
(c) ‘epha’
(d) ‘EPHA’
Answer:
(d) ‘EPHA’
Question 10.
Write the missing file opening mode in the blank provided to open the file for reading and writing.
import pickle fobj=open(“emp.dat","____________") rec=pickle.load(fobj) print(rec) fobj.close()
Answer:
rb+
Question 11.
State True or False:
Exception handling is done using the “exception” block
Answer:
False
Question 12.
Which of the following is the correct way of storing information of customers named ‘Paritosh’ and ‘Bhavesh’ for the option chosen above?
(a) customers = {'Pari tosh':24, ['Printed paper', ‘Pen stand’], 3409, ‘Bhavesh’: 45, [‘A4 Rim’,‘Printer Cartridge’, ‘Pen Carton’, ‘gift Wrap’], 8099.99} (b) customers={‘Pari tosh’:[24,[Printed Paper’, ‘Pen stand’], 3409],‘Bhavesh’: [45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘gift Wrap’], 8099.99]} (c) customers=[‘Paritosh’:24,‘Printed Paper’, ‘Penstand’, 3409, ‘Bhavesh’: 45, ‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘gift Wrap’, 8099.99] (d) customers=(‘Paritosh’:24,[Printed Paper’, ‘Penstand’], 3409, ‘Bhavesh’: 45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘gift Wrap’], 8099.99)
Answer:
(a) customers = {'Paritosh':24,['Printed paper', ‘Pen stand’], 3409, ‘Bhavesh’: 45, [‘A4 Rim’,‘Printer Cartridge’, ‘Pen Carton’, ‘gift Wrap’], 8099.99}
Question 13.
Which SQL statement is used to retrieve unique values from a column?
Answer:
(d) SELECT DISTINCT
Question 14.
What will the following query do?
Alter table Accounts Add Primary key(AID);
(a) Create the table Accounts with AID as Primary key
(b) Add the column “primary key” to the table.
(c) Assign Primary key constraint to the AID column.
(d) None of the above
Answer:
(c) Assign Primary key constraint to the AID column.
Question 15.
The relation between Primary key, Candidate key and Alternate key is
(a) Primary key = Candidate key – Alternate key
(b) Candidate key = Primary key – Alternate key
(c) Alternate key = Primary key + Candidate key
(d) None of the above
Answer:
(a) Primary key = Candidate key – Alternate key
Question 16.
The ____________ command can be used to remove all records of a table along with the table structure.
(a) DELETE TABLE
(b) DROP TABLE
(c) REMOVE TABLE
(d) None of these
Answer:
(b) DROP TABLE
Question 17.
Frequency is Measured in
(a) Cycles per second
(b) Hertz
(c) Both (a) and (b)
(d) None of these
Answer:
(c) Both (a) and (b)
Question 18.
The main computer in any network is called as
(a) Client
(b) Server
(c) Switch
(d) Hub
Answer:
(b) Server
Question 19.
Which protocol is used to transfer files from one host to another over a TCP-based network?
Answer:
(b) FTP (File Transfer Protocol)
Directions (Q. 20 and Q. 21) are Assertion(A) and Reason(R) 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
Question 20.
Assertion (A): A file that is opened using the open() function may not specify its opening mode.
Reason (R): If the mode is not specified , the read mode is used by default.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Question 21.
Assertion (A): Referential integrity is a system of rules of DBMS.
Reason (R): It ensures that users don’t accidentally delete or change related data.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Section B
(7 × 2 = 14)
Question 22.
Write the method to perform the following.
(a) To get a sorted list of the keys of a dictionary
(b) To get the number of key:value pairs in a dictionary.
Answer:
(a) sorted()
(b) len()
Question 23.
Name the Python library modules which need to be imported to invoke the following functions:
(i) load()
(ii) pow()
Answer:
(i) load() – pickle
(ii) pow() – math
Question 24.
(i) Identify the proper operators to be used for the following cases:
(a) To find the exponent of a number
Or
(b) To find the remainder of a division
(ii) Identify proper functions for the following cases:
(a) To check whether a substring exists in a string or not.
Or
(b) To check whether a string comprises of digits only.
Answer:
(i) (a) **
Or
(b) %
(ii) (a) find()
Or
(b) isdigit()
Question 25.
Study the following program and select the possible output(s) from the options (a) to (d) following it. Also, write the maximum and the minimum values that can be assigned to the variable Y.
import random
X=random.random()
Y=random.randint(0,4)
print int(X), “:”, Y+int(X)
(a) 0 : 0
(b) 1 : 6
(c) 2 : 4
(d) 0 : 3
Answer:
(a) and (d) are the possible output(s)
Minimum value that can be assigned to Y = 0
Maximum value assigned to Y = 3
Question 26.
A table, ITEM has been created in a database with the following fields:
ITEMCODE, ITEMNAME, QTY, PRICE
(i) Give the SQL command to add a new field, DISCOUNT (of type Integer) to the ITEM table.
(ii) Which category of SQL commands does the command used, belong to?
Answer:
(i) Alter table ITEM ADD DISCOUNT integer;
(ii) DDL
Question 27.
(i) Write function names to be used for the following purposes.
(a) To remove extra spaces from both sides of a string.
Or
(b) To find the monthname of a date.
(ii) Write constraints to be used for the following cases:
(a) To restrict salaries <10000 in the sal field of EMP table
Or
(b) To restrict NULL values in the ename column of the EMP table.
Answer:
(i) (a) trim()
Or
(b) monthname()
(ii) (a) CHECK
Or
(b) NOT NULL
Question 28.
(a) Write the full form of the following.
(i) GNU
(ii) XML
Or
(b) Briefly discuss the role of a web browser in Internet surfing.
Answer:
(a) (i) GNU – GNU’s, not Unix
(ii) XML – eXtensibleMarkup Language
Or
(b) A web browser is a software program allowing users to locate and display web pages.
Section C
(3 × 3 = 9)
Question 29.
A binary file “emp.dat” contains records of employees as per the following structure:
Write a program in Python to open the Binary file “emp.dat” and display only those records where the employee salary is greater than 75000.
Or
Write a program to read the content from a text file “status.txt”, count and display the total number of lines and blank spaces present in it. e.g. if the “status.txt” file contains the following lines:
Welcome to your one-stop solutions for all your study, practice, and assessment needs for various competitive & recruitment examinations and school segments. We have been working tirelessly for over a decade to ensure you have best-in-class study resources because you deserve SUCCESS AND NOTHING LESS…
The output will be:
The status file contents are
Total lines in the file are: 4
The total spaces in the file are: 43
Answer:
import pickle f=open("emp.dat","rb") while True: try: lst=pickle.load(f) if(lst[2]>75000): print("Employee No. :", lst[0]) print("Employee Name :", lst[1]) print("Employee Salary :", lst[2]) except EOFError: print("No more records") break f.close() Or import os tfile=‘status.txt’ if os.path.isfile(tfile): fob=open(tfile.‘r’) blankspaces=total_lines=0 print("The status file contents are") print (“----------’’) while True: aline=fob.readline() if not aline: break else: total_lines=total_lines+1 aline=aline.rstrip() for i in aline: if i.isspace(): blankspaces=blankspaces+1 print('Total lines in file are:",total_lines) print("Total space in file are:", blankspaces) fob. closed() else: print(“File does not exist”)
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.
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
Or
Alam has a list containing 10 integers. You need to help him create a program with separate user-defined functions to perform the given operations based on this list.
Traverse the content of the list and push the even numbers into a stack.
Pop and display the content of the stack.
For example, If the sample content of the list is as follows.
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
38 22 98 56 34 12
Answer:
R={"0M":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 Or N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38] def PUSH(S,N): S.append(N) def POP(S): if S!=[ ]: return S.pop() else: return None ST=[ ] for k in N: if k%2==0: PUSH(ST,k) while True: if ST!=[ ]: print(POP(ST),end=" ") else: break
Question 31.
Consider the table Person:
(a) Write statements to
(i) Display the Unique Cities.
(ii) Display Firstnames of people who do not have an address.
(iii) Display the last name and city of person whose first name starts with K.
Or
(b) (i) Display the person ID and first name who live in Sandnes.
(ii) Change city to “Melbourne” for records whose Firstname ends with “K”.
(iii) Increase the width of the column Firstname to varchar(45)
Answer:
(a) (i) SELECT DISTINCT City FROM Person; (ii) SELECT FirstName FROM Person WHERE Address IS NULL; (iii) SELECT LastName, City FROM Person WHERE FirstName LIKE "K%"; Or (b) (i) SELECT P_Id, FirstName FROM Person WHERE City = "Sandnes"; (ii) UPDATE Person set CITY = “Mel bcAirne” where Firstname like “%K”; (iii) ALTER table Person modify Firstname varchar(45);
Section D
(4 × 4 = 16)
Question 32.
(A) (i) What are compile time errors? Give an example.
(ii) What output will the following code produce: if x=10, y=0
try: n1=int(input("Enter a number :")) n2=int(input("Enter a number :")) print(n1//n2) except: print("Some Error occured") else: print("No Error")
Or
(B) (i) What are run-time errors? Give an example.
(ii) What output will the following code produce: if x=100, y=10
try: n1=int(input(“Enter a number :”)) n2=int(input(“Enter a number :”)) print(n1//n2) except: print("Some Error occured") else: print("No Error")
Answer:
(A) (i) Compile time errors are the errors that are usually detected during program compilation and can be easily detected.
Example: Syntax error, Semantic error.
(ii) Output: Some Error occured
Or
(B) (i) Run time errors are the ones that occur during a program run and are difficult to detect.
Example: Hardware error, File not found, etc.
(ii) Output:
10
No Error
Question 33.
(a) Why csv files are called so?
(b) Write a Python program to perform the following using functions as follows:
copytocsv(): ACSV file “marks.csv” has name, class, and marks separated by a comma. Write the Python function to copy only the name and class to another CSV file “class.csv”.
copyselected(): The CSV file “marks.csv” has name, class, and marks separated by a comma. Write the Python function to copy only rows of students of class 2 to another CSV file “class.csv”.
Answer:
(a) csv files are comma-separated files and the records are delimited using the ‘,’ character.
(b) import csv def copytocsv(): file = open('class.csv', 'w', newline=" ") writer = csv.writer(file) with open('marks.csv') as csvfile: data = csv.reader(csvfile) for row in data: writer.writerow([row[0], row[1]]) file.close() def copyselected(): file = open('class.csv'. 'w', newline="\n") w1 = csv.writer(file) with open('marks.csv') as csvfile: data = csv.reader(csvfile) for row in data: if row[1]== '2': writer.writerow(row) file.close() copytocsv() copyselected()
Question 34.
Study the following tables Doctor and Salary and write SQL commands for the following:
(i) Display NAME of all doctors who are in MEDICINE department having more than lOyrs experience from the table Doctor.
(ii) Display the average salary of all doctors working in ENT department using the tables Doctor and Salary.
Salary = BASIC + ALLOWANCE.
(iii) Display the minimum ALLOWANCE of female doctors.
(iv) (A) Display the highest consultation fee among all male doctors.
Or
(B) To display the detail of doctor who have experience more than 12 years.
Answer:
(i) Select NAME from Doctor where DEPT = ‘MEDICINE’ AND EXPERIENCE > 10; (ii) Select AVG(BASIC + ALLOWANCE) FROM Salary where Salary.ID IN(Select ID from Doctor where DEPT = ‘ENT’); (iii) Select MIN(ALLOWANCE) FROM Salary where Salary.ID IN(SELECT ID from Doctor where SEX = ‘F’); (iv) (A) Select MAX(CONSULTATION) FROM Salary where Salary.ID IN(Select ID from Doctor where SEX = ‘M’); Or (B) Select * from Doctor where EXPERIENCE>12;
Question 35.
Write an example code to fetch a single record from a database.
Use the following information for connectivity:
Database: PythonDB
Table: Library
Host: localhost
UsedID: root
Password: Library@123
Answer:
import mysql.connector con = mysql.connector.connect(host = "localhost", user = "root", passwd = "Library@123", database= “PythonDB”) cursor = con.cursor(.) try: cursor.execute ("Select Name. Roll No, Address, Percentage from Student") rec = cursor. fetchone() print(rec) except: con.roll back() con.close()
Section E
(2 × 5 = 10)
Question 36.
(a) Which module is used to operate on CSV file?
(b) Write a Python program with following functions:
addcsv(): File old.csv has come from branch in Pune and it needs to be added to file “updated.csv” which has data for all branches. Write the code in the function to perform the same.
convertcsv(): A file old.csv has come with separator but your system can only read ‘;’
Write a program to convert to “converted.csv” file. Write the function to change the separator of the file.
Answer:
(a) To read and write in CSV files we need to import csv module.
(b) import csv defaddcsv(): f1 = open("old.csv", 'r') f2 = open("updated.csv", 'a', newline= "\n") r1 = csv.reader(f1) w1 = csv.writer(f2) for row in r1: w1.writerow(row) f1.close() f2.close() defconvertcsv(): f1 = open("old.csv", 'r') f2 = open("converted.csv", 'w', newline = "\n") r1 = csv.reader(f1, delimiter = ";") w1 = csv.writer(f2, delimiter = ";") for row in r1: w1.writerow(row) f1.close() f2.close() addcsv() convertcsv()
Question 37.
Freshminds University of India is starting its first campus in Ana Nagar of South India with its centre admission office in Kolkata. The university has three major blocks comprising of Office block, Science block, and a Commerce block ina 5 km area campus.
As a network expert, you need to suggest the network plan as per (a) to (e) to the authorities keeping in mind the distance and other given parameters.
Expected wire distance between various locations
Expected number of computers to be installed at various locations in the university
(a) Suggest the authorities, the cable layout amongst various blocks inside university campus for connecting the blocks.
(b) Suggest the most suitable place (i.e. block) to house the server for this university with a suitable reason.
(c) Suggest an efficient device from the following to be installed in each of the block to connect all the computers.
(i) Modem
(ii) Switch
(iii) Gateway
(d) Suggest a suitable topology to connect the computers in each building.
(e) (i) The university is planning to connect its campus in Kolkata which is more than 100 km.
Which type of network will be formed?
Or
(ii) Suggest a suitable guided transmission medium to connect to the Kolkata campus.
Answer:
(a)
(b) The most suitable place to house the server is Science Block as it has a maximum number of computers. Thus, reducing the cabling cost and increasing the efficiency of the network.
(c) (ii) Switch is the device to be installed in each of the blocks to connect all the computers.
(d) Star topology, as it is the best in efficiency.
(e) (i) WAN (Wide Area Network) will be formed.
Or
(ii) Optical fiber cable