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 Allowed: 3 hours
Maximum Marks: 70
General Instructions:
- This question paper contains five sections, Section A to E.
- All questions are compulsory.
- Section A have 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.
Section – A
Question 1.
State True or False.
k = 2 + 31 is a complex number in Python [1]
Answer:
False
Explanation:
Complex number is a number expressed in the form a + bi, where a (real part) and bi is the imaginary part
Question 2.
Which of the following is the correct output for the execution of the following Python statement? print(5 + 3 **2/2)
(A) 32
(B) 8.0
(C) 9.5
(D) 32.0
Answer:
(C) 9.5
Explanation:
5 + 3**2/2 = 5 + 9/2
= 5 + 4.5 = 9.5
Question 3.
Which of the following is true for variable names in Python? [1]
(A) unlimited length
(B) all private members must have leading and trailing underscores
(C) underscore and ampersand are the only two special characters allowed
(D) none of the mentioned
Answer:
(A) unlimited length
Explanation:
Variable is a container object that stores a meaningful value that can be used throughout the program. Each variable has a specific type, which determines the size and layout of the variable memory, and the set of operations that can be applied do the variable
Question 4.
To access a list which contains 5 elements, which of the following uses of range() would produce a list of the desired indexes? [1]
(A) range(1,5)
(B) range(0,4)
(C) range(5)
(D) range(1,6)
Answer:
(C) range(5)
Explanation:
The range() is a built-in function in Python. Syntax of range() function is: range([start], stop[, step])
The start and step parameters are optional. If start value is not specified, by default the list starts from 0. If step is also not specified, by default the value increases by 1 in each iteration. All parameters of range() function must be integers. The step parameter can be a positive or a negative integer excluding zero.
Commonly Made Error:
Sometimes students miss the correct syntax of built-in-functions.
Answering Tip:
Students should remember the correct syntax of all built-in functions
Question 5.
Which term describes a loop that continues repeating without a terminating (ending) condition? [1]
(A) Infinite Loop
(B) Conditional Loop
(C) Unlimited Loop
(D) Sequence Loop
Answer:
(A) Infinite Loop
Explanation:
When the condition becomes false, the loop terminates. It is the responsibility of the programmer to ensure that this condition eventually does become false so that there is an exit condition and it does not become an infinite loop.
Question 6.
Which of these about a dictionary is false? [1]
(A) The values of a dictionary can be accessed using keys.
(B) The keys of a dictionary can be accessed using values.
(C) Dictionaries aren’t ordered.
(D) Dictionaries are mutable.
Answer:
(B) The keys of a dictionary can be accessed using values.
Explanation:
keys of a dictionary are unique while values can be duplicate. So values can be accessed by specifying a key but not vice versa. Values are accessed as <dict_name>[key].
Question 7.
Fill in the blank
Removing errors from the programs is known as ……………………………. [1]
(A) Testing
(B) Debugging
(C) Documentation
(D) None of the above
Answer:
(B) Debugging
Explanation:
Testing is the process using which we find errors and bugs. Debugging is the process using which we correct the bugs that we found during the testing process.
Question 8.
Which of the following are used in data definition? [1]
(A) DML
(B) DDL
(C) TCL
(D) None of these
Answer:
(B) DDL
Explanation:
DDL (Data Definition Language) are the commands that allow you to perform tasks like creating, altering and dropping database, granting and revoking privileges on database and maintaining commands
Question 9.
Which of the following is not a function/method of the random module in Python [1]
(A) randfloat()
(B) randint()
(C) random()
(D) randrange()
Answer:
(A) randfloat()
Explanation:
There is no such function is available in the random module.
Question 10.
Fill in the blank
…………………………… method is used to retrieve the original data that was changed through the commit() method. [1]
(A) execute()
(B) rollback()
(C) update ()
(D) close()
Answer:
(B) rollback()
Explanation:
The rollback() method is used to revert the last changes made to the database.
Question 11.
……………………………… are the values provided in function call/invoke statement. [1]
(A) Functions
(B) Arguments
(C) Preprocessor
(D) Models
Answer:
(B) Arguments
Explanation:
Arguments are the values provided in function call/invoke statement. A function is a block of organised and reusable code that is used to perform a single, related action
Question 12.
Fill in the blank
……………………….. is an attribute whose value is derived from the primary key of some other table. [1]
(A) Primary key
(B) Foreign key
(C) Alternate key
(D) None of these
Answer:
(B) Foreign key
Explanation:
A foreign key is a column or a group of columns in a relational database table that provides a link between data in two tables.
Question 13.
Fill in the blank
Bus Topology is also called as ………………………. [1]
(A) Circular topology
(B) Linear topology
(C) Ring topology
(D) Hybrid topology
Answer:
(B) Linear topology
Explanation:
The computers in bus topology are connected one after the other in a sequential chain with a single transmission medium, therefore known as linear topology
Question 14.
Which of the following statement is not correct? [1]
(A) We can write content into a text file opened using ‘w’ mode
(B) We can write content into a text file opened using ‘w+’ mode
(C) We can write content into a text file opened using ‘r’ mode
(D) We can write content into a text file opened using ‘r+’ mode
Answer:
(C) We can write content into a text file opened using ‘r’ mode
Explanation:
r: Opens the file in read-only mode. So, we can’t write any data to the file.
Question 15.
Which function is used with ORDER BY clause to customise sort order? [1]
(A) ASC
(B) DESC
(C) FIELD
(D) None of these
Answer:
(C) FIELD
Explanation:
The FIELD function internally maps the values specifying order to a list of numeric values and then uses those numbers for sorting.
Question 16.
Exception raised when the relational integrity of the database is affected in Python [1]
(A) IntegrityFailError
(B) IntegrityFailure
(C) IntegrityViolationError
(D) IntegrityError
Answer:
(D) IntegrityError
Explanation:
Relational integrity refers to the relationship between tables which is done using primary and foreign keys. Whenever an error such as, duplicate key is inserted or a foreign key constraint would fail, occurs the Integrity Error exception is raised.
Assertion and Reason:
In the following questions, A statement of Assertion (A) is followed by a statement of Reason (R). 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 correct explanation for A.
(C) A is true but R is false.
(D) A is false but R is true.
Question 17.
Assertion (A): It is not possible to delete/remove element(s) from the list.
Reason (R): The pop(), remove() and del() functions are used to delete/remove items from the list. [1]
Answer:
(D) A is false but R is true.
Explanation:
It is possible to delete/remove element(s) from the list. There are many ways of doing so:
(i) If index is known, we can use pop() or del
(ii) If the element is known, not the index, remove() can be used.
(iii) To remove more than one element, del() with list slice can be used.
Question 18.
Assertion (A): ZeroDivisionError is raised when the second operand of a division or module operation is zero.
Reason (R): Illegal operations can raise exceptions. [1]
Answer:
(A) Both A and R are true and R is the correct explanation for A.
Explanation:
Illegal operations can raise exceptions. There are plenty of built-in exceptions in Python that are raised when corresponding errors occur. We can view all the built-in exceptions using the built-in local() function as follows:
print(dir(locals()[‘ builtins ‘]))
Section – B
Question 19.
Consider the code given below A
i = 0
while i<100:
i + = 1
if i % 2 = 0
print(i)
This code was written to print values less than 100 but not 100. If the loop condition is not to be changed, find the error and rewrite the code. [2]
Answer:
i = 0
while i<100:
if i*2==0:
print(i)
i +=1
Question 20.
Identify the domain name and URL from the following: http://www.income.in/home.aboutus. html [2]
OR
Differentiate between web server and web browser. Write any two popular web browsers.
Answer:
Domain name – income.in
URL-http://www.income.in/home.aboutus.html
OR
Web Browser: A web browser is a software application for accessing information on the World Wide Web. When a user requests a web page from a particular website, the web browser retrieves the necessary content from a web server and then displays the page on the user’s device. Web Server: A web server is a computer that runs websites. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP).
Popular web browsers: Google Chrome, Mozilla Firefox, Internet Explorer, etc
Question 21.
(a) Predict the output of the following code.
md= {‘a’ll.’b’^’c’iS}
md [ d’]=4
print(md)
(b) What would be the output produced by the following code”
def hey(n,m):
return m-n
hey (hey (3,4) , 5) [2]
Answer:
(a) {‘a’: 1, ‘b’: 2, ‘c’: 3, ‘d’: 4}
(b) 4
Question 22.
How is a database connection established? What is a cursor? [2]
Answer:
Each database module needs to provide a connect function that returns a connection object. The parameter that are passed to connect vary by the module and what is required to communicate with the database.
A cursor is a Python object that enables you to work with the database. In dataset terms, the cursor is positioned at a particular location within a table or tables in a database.
Question 23.
(a) How many pair of wires are there in twisted pair cable(Ethernet)?
(b) What is the name of port, which is used to connect Ethernet cable to a computer or a laptop? [2]
Answer:
(a) Two insulated copper wires
(b) Ethernet port
Question 24.
What is the output of the given program? [2]
runs=40
while runs>1:
runs=runs/2-1
print(runs,)
OR
Find the output of the following code:
a= [[[1,2,3,4,5] , [6,7,8]] , 9] <
a[-1]=200
b=a [: ] ‘
b[0] [0] [3]=17
print(a)
print (b) [2]
Answer:
19.0
8.5
3.25
0.625
OR
[[[1, 2, 3, 17, 5], [6, 7, 8]], 200]
[[[1, 2, 3, 17, 5], [6, 7, 8]], 200]
Question 25.
What is the default format for “Datetime” & “Timestamp” data type? What is the maximum length of the char columns? [2]
OR I
A table Employee has 8 columns but no row. Later, 8 new rows are inserted and 2 rows are deleted in the table.
What is the degree and cardinality of the table Employee?
Answer:
YYYY-MM-DD hh:mm:ss
255 bytes
OR
Degree = 8 (No. of columns)
Cardinality = 8 – 2 = 6 (no. of rows)
Section – C
Question 26.
(a) Based on the tables ‘Watches’ and Sale given below.
Table: Sale
Watchid | Qty_Sold | Quarter |
wool | 10 | 1 |
W003 | 5 | 1 |
W002 | 20 | 2 |
W003 | 10 | 2 |
woo1 | 15 | 3 |
W002 | 20 | 3 |
W005 | 10 | 3 |
W003 | 15 | 4 |
WHAT WILL BE THE OUTPUT OF THE QUERY
select watch_name, price, type from watches w, sale s where w. watchid!=s.watchid;
(b) Obtain the outputs of the following SQL queries based on the data given in tables ITEMS and TRADERS.
Table: TRADERS
TCODE | TNAME | CITY |
T01 | ELECTRONIC SALES | MUMBAI |
T03 | BUSY STORE CORP | DELHI |
T02 | DISP HOUSE INC | CHENNAI |
(i) SELECT MAX (PRICE), MIN (PRICE) FROM ITEMS;
(ii) SELECT PRICE*QTY FROM ITEMS WHERE CODE=1004;
(iii) SELECT* FROM ITEMS ORDER BY INAME ASC;
(iv) SELECT INAME, PRICE FROM ITEMS WHERE PRICE > = 10000 AND PRICE < = 22000; [3]
Answer:
(a)
watch_name | price | type |
High Fashion | 7000 | Unisex |
(b) (i) 38000 1200
(ii) 1075000
(iii)
(iv) DIGITAL PAD 12I 11000
CAR GPS SYSTEM 21500
Question 27.
Define a function reverse () that overwrites the contents of the file “myfile.txt” with its reverse contexts. That is the file will now contain the lines of the original file in reverse order. [3]
OR
Consider the file “Poem.txt”
Autumn Song
Like a joy on the heart of a sorrow,
The sunset hangs on a clouds:
A golden storm of glittering sheaves,
Of fair and frail and flattering leaves,
The build wind blows in a cloud.
Define a function reverse() that prints the lines of the file in reverse order
Answer:
def reverse(): file=open("myfile.txt","r") text=file.readlines() file.close() n=len(text) file=open("myfile.txt","W") for i in range (n-1,-1,-1): file.writeline(text[1]) file.close()
OR
def reverse(): file=open("Poem.txt","r") text=file.readlines() file.close() line=len(text) for i in range (line-1,-1,-1): print(text[i])
Question 28.
(a) Consider the following tables WORKER and PAYLEVEL and give output for (i) to (iv).
Table: PAYLEVEL
PLEVEL | PAY | ALLOWANCE |
P001 | 26000 | 12000 |
P002 | 22000 | 10000 |
P003 | 12000 | 6000 |
(i) SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
(ii) SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
(iii) SELECT NAME FROM WORKER ORDER BY DOB DESC;
(iv) SELECT NAME, DESIGN FROM WORKER WHERE PLEVEL=”P001″;
(b) In a Database, there are two tables with the instances given below:
Write the statement to delete a column phone from the table students. [3]
Answer:
(a)
(i)
COUNT (PLEVEL) | PLEVEL |
1 | P001 |
2 | P002 |
2 | P003 |
(ii)
Max (DOB) | Min (DOJ) |
12-Jul-1987 | 13-Sep-2004 |
(iii) Name
Chander Nath
Ameen Ahmed
Fizza
Sanya
Radhe Shyam
(iv)
Name | Design |
Radhe Shyam | Supervisor |
(b) ALTER TABLE STUDENTS DROP PHONE;
Question 29.
Write a function that takes one argument (a positive integer) and reports if the argument is prime or not. [3]
Answer:
def prime(n): for i in range (2,n/2): if n*i==0: print(n, "is not prime") return print(n, "is prime") return
Question 30.
Write a program to print a string in reverse order. For this write the following two functions. [3]
(i) pushStack() – To extract individual characters from string and push in a stack.
(ii) PopStack – To pop the stack and display the string.
OR
Write a program that checks whether an input string is a palindrome using stacks. Write two functions.
(i) pushstr()
(ii) popstr () Also write the main module.
Answer:
def pushStack(stack,ch): stack.append(ch) top=len(stack)-1 return def popStack(stack): if isEmpty(stack): return else: top=len(stack)-1 for a in range(top-1,-1,-1): print(stack[a]) stk= [] top=none str=input("Enter a string") while a in str: pushStack(stk,a) print("Reverse") popStack(stk)
OR
def pushstr(stk,str): top=0 for i in range in(str) stk.append(str[i]) topt=1 return top def popstr(stk): if stk=[]: return None else: return(stk.pop()) str=input("enter a string") strstack=[""]len(str) top=pushstr(strstack, str) for i in range str.(str): if NOT (str[i]==popstr(strstack)): print("Not a palindreme") break else: print("string is a palindrome")
Section – D
Question 31.
Uplifting Skills Hub India is a knowledge and skill community which has an aim to uplift the standard of knowledge and skills in the society. It is planning to setup its training centres in multiple towns and villages pan India with its head offices in the nearest cities. They have created a model of their network with a city, a town and 3 villages as follows.
As a network consultant, you have to suggest the best network related solutions for their issues/ problems raised in (i) to (v) keeping in mind the distance between various locations and given parameters.
Shortest distance between various location :
VILLAGE 1 to B_TOWN | 2 KM |
VILLAGE 2 to B_TOWN | 1.0 KM |
VILLAGE 3 to BJTOWN | 1.5 KM |
VILLAGE 1 to VILLAGE 2 | 3.5 KM |
VILLAGE 1 to VILLAGE 3 | 4.5 KM |
VILLAGE 2 to VILLAGE 3 | 2.5 KM |
A_CITY Head Office to B_HUB | 25 KM |
Number of Computers installed at various locations are as follows :
B_TOWN | 120 |
VILLAGE 1 | 15 |
VILLAGE 2 | 10 |
VILLAGE 3 | 15 |
A_CITY Head OFFICE | 6 |
Note:
- In Villages, there are community centres, in which one room has been given as training centre to this organization to install computers.
- The organization has got financial support from the government and top IT companies.
(i) Suggest the most appropriate location of the SERVER in the B_HUB out of the 4 locations, to get the best and effective connectivity. Justify your answer.
(ii) Suggest the best wired medium and draw the cable layout (location to location) to efficiently connect various locations within the B_HUB.
(iii) Which hardware device will you suggest to connect all the computers within each location of B_HUB ?
(iv) Which service/protocol will be most helpful to conduct live interactions of Experts from Head Office and people at all locations of B_HUB ?
(v) The community is planning to link its blocks situated in various part of the same city. Which type of network out of LAN, WAN, MAN will be formed? Justify. [2+3=5]
Answer:
(i) B_TOWN can house the server as it has the maximum no. of computers.
(ii) Optical fibre cable is the best for this star topology.
(iii) Switch
(iv) VoIP
(v) MAN (Metropolitan Area Network) will be formed as network would span within a city.
Question 32.
(a) PREDICT OUTPUT OF THE CODE GIVEN BELOW
1st= [1,2,3]
myvar=lst[1]
1st [1]=67
print(1st)
print(myvar)
(b) Write Python code to increase age of all employees by 1 year in the Employee table of database HTMdb with userid HRMan and password HRMANexe@pwd.
OR
(a) PREDICT OUTPUT OF THE FOLLOWING CODE
myvar=45
1st=[myvar,2,3]
myvar=89
1st [1]=67
print(1st)
print(myvar)
(b) Write Python code to delete all the records from the Employee table whose age >60 and the table has following fields.
Empid, EmpName, Deptid, age, Payscale [5]
Answer:
(a) [45, 67, 3]
(b) import MySQLdb db = MySQLdb.connect(‘localhost’, ‘HRMan’, ‘HRMANexe@pwd’, ‘HTMdb’) cursor = db.cursor() sql = ”””UPDATE Employee set Age=Age+1 where SEX=’%c’ /(‘M’)””” try: db.execute(sql) db.commit() except: db.rollback() db.close()
OR
(a) [45, 67, 3]
89
(b) import MySQLdb db = MySQLdb.connect(‘localhost’, ‘HRMan’, ‘HRManexe@pwd’, ‘Employee’) cursor = db.cursor() sql = “Delete from Employee where AGE>’%d’/ (60) try: db.execute(sql) db.commit() except: db.rollback() db.close()
Question 33.
WHAT IS THE SPECIAL CHARACTER THAT TERMINATES EACH LINE OF A TEXT FILE CALLED? fST!
A csv file students .csv contains students name score. Write a function
(i) score() – to read students name and score from the file and print
(ii) count() – to count the number of records and column names present in the file. [5]
OR
WHAT IS THE FILE EXTENSION USED FOR TEXT FILES?
Define a function overwrite() that writes the contents of the file “poem.txt” to another file ‘newpoem.txt”, which
already exists. The function overwrites the contexts of the file “newpoem.txt”
Answer:
EOL(END OF LINE) import csv def score(): with open('students.csv',newline='n') as . f data=csv.DictReader(f) print("StudentName","\","score" , ) for i in data: print(i['StudentName'] ,"&t",i [' score']): def count() field= [] rows= [] with open('students.csv',newline='n') as f: data=csv.reader(f) fields =next (data) print (' Field names are: ) for field in fields: print(field,"\t") print() print("\n Total number of rows" len(data))
OR
TXT def overwrite(): file1=open("Poem.txt","r") file2=open("newpoem.txt","w") text=file.readlines() file1.close() file2.writelines(text) file2.close()
Section – E
Question 34.
BASED ON THE TABLE GIVEN BELOW ANSWER THE QUESTIONS THAT FOLLOW
Patients
(i) What is the degree and cardinality of the above table? [1]
(ii) identify the primary key and foreign key for the table. [1]
(iii) Write appropriate command to :
(a) add record of patient no 6 name Kritika, department gynae and doctor id as 300.
(b) delete the record of patient number 4 [2]
OR (Option for part iii only)
(iii) Write commands to
(a) display records of all the patients of doctor with id 200.
(b) display records of all the patients of ortho department.
Answer:
(i) degree :4
cardinality: 5
(ii) primary key: PatNo
foreign key: DocID
(iii) (a) Insert into patients(PatNo, PatName, Dept, DocID) values(6,”Kritika”,”Gynae”,300)
(b) delete from patients where PatNO=4
OR
(iii) (a) Select * from patients where DocID =200
(b) Select * from patients where Dept=”Ortho”
Question 35.
Consider the code given below, written the count the and return the number of books written by an author, from the data stored in the file Book.dat
Each record in the file contains:
Book Number, Book Name and author name stored in this order.
Some parts of the code in missing. Complete the code by answering the questions that follow import pickle
def countrec (Author): fobj = _____________ #Statement-1 num=0 try: while_____________ #Statement-2 rec=_____________ #Statement-3 if Author= num=num+1 except: fobj ._____________ #Statement-4 return
(i) Statement 1 opens the binary file for reading. What code should be written in it?
(ii) Statement 2 iterates the file to read the records. What should be written to complete it?
(iii) Statement 3 write code to read the records and in statement 4 write the code to be executed when exception is raised while reading the records. (1+1+2)
Answer:
(i) open(“Bookdat”,”rb”)
(ii) True
(iii) Pickle.load(fobj).close()