Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 11 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 11 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.
Integer is a mutable data type in Python.
Answer:
False
Question 2.
Identify the output of the following Python statement:
b = 1 for a in range(1, 10, 2): b += a + 2 print(b)
(a) 31
(b) 33
(c) 36
(d) 39
Answer:
(c) 36
Question 3.
Which of the following Python functions displays the memory id of a variable?
(a) type()
(b) str()
(c) getid()
(d) id()
Answer:
(d) id()
Question 4.
Given s=”AISSE@2023″. What will be the output of s([:: -1])?
(a) ‘3202@ESSIA’
(b) 3
(c) AISSE
(d) ESSIA
Answer:
(a) ‘3202@ESSIA’
Question 5.
What will be the output of the following code?
s = "cbse sample paper" s.capitalize() print(s)
Answer:
Cbse sample paper
Question 6.
What will be the output of the following code?
l1 = [3,4,5,6] l2 = [1,4,2,7] l2 = l1 print(l1==l2)
(a) False
(b) True
(c) 12
(d) Error
Answer:
(b) True
Question 7.
Suppose d = {“john”:40, “peter”:45), to delete the entry for “john” what command do we use?
(a) d.delete(“john”:40)
(b) d.delete(“john”)
(c) del d[“john”]
(d) del d(“john”:40)
Answer:
(c) del d[“john”]
Question 8.
Which of the following operators performs an integer division?
(a) *
(b) //
(c) /
(d) **
Answer:
(b) //
Question 9.
What is the output of the following Python statements?
b = 1 for a in range(1, 10, 2): b += a + 2 print(b)
(a) 31
(b) 33
(c) 36
(d) 39
Answer:
(c) 36
Question 10.
Write the missing statement to complete the following code:
f=open("myfile.txt', "r") f.__________ #To place the file pointer 10 positions forward. data=f.read(20) print(data)
Answer:
seek(10)
Question 11.
State True or False:
The final block may not execute even once in a code.
Answer:
False
Question 12.
What will be the output of the last print statement?
x = 50 def func(x): print('x is', x) x = 2 print('Changed local x to', x) func(x) print('x is now', x)
(a) x is now 50
(b) x is now 2
(c) x is now 100
(d) None of these
Answer:
(a) x is now 50
Question 13.
Write the SQL command that adds a new column in the existing table.
Answer:
ALTER Table table_name ADD column_namedata_type:
Question 14.
What will be the output of the following query:
Select Dept, Count(*) from Emp Group by Dept:
(a) Displays the total number of employee records.
(b) Displays number of departments
(c) Displays department-wise count of employees.
(d) Displays the unique department names.
Answer:
(c) Displays department-wise count of employees.
Question 15.
Which of the following functions returns the total number of values?
(a) MAX
(b) MIN
(c) COUNT
(d) SUM
Answer:
(c) COUNT
Question 16.
The __________ clause can group records based on common values in a field.
(a) AGGREGATE
(b) GROUP BY
(c) GROUP
(d) JOIN
Answer:
(b) GROUP BY
Question 17.
Which of the following is the communication protocol that sets the standard used by every computer that accesses web-based information?
(a) XML
(b) HTML
(c) HTTP
(d) None of these
Answer:
(c) HTTP
Question 18.
Which among the following is the fastest-guided media
(a) Telephone cable
(b) Coaxial cable
(c) Ethernet
(d) Optical fibre cable
Answer:
(d) Optical fibre cable
Question 19.
Which network protocol ensures that data is sent and received in the correct order, and can handle retransmission of lost packets to maintain data integrity?
Answer:
TCP (Transmission Control Protocol)
Directions (Q. 20 and 21) are Assertion (A) and Reason (R) based questions. Mark the correct choice as
(a) Both A and R are true and R is a correct explanation of A.
(b) Both A and R are true but R is not a correct explanation of A.
(c) A is true and R is false.
(d) A is false and R is true.
Question 20.
Assertion (A): A Python function that accepts parameters can be called without any parameters.
Reason (R): Functions can carry default values used, whenever values are not received from the calling function.
Answer:
(a) Both A and R are true and R is the correct explanation of A.
Question 21.
Assertion (A): Sum(), count(), max(), min() are all aggregate functions.
Reason (R): They work on single records.
Answer:
(c) A is True but R is False.
Section B
(7 × 2 = 14)
Question 22.
Write Python statements using built-in functions only for performing the following tasks:
(i) To cause tup_of_dict((1, ‘one’), (5, ‘five’)) to return {1: ‘one’, 5: ‘five’} to dictionary
def tup_of_tuples_to_dict(tup_of_tuples): dictionary = {} for tup in tup_of_tuples: # insert code snippet here return dictionary
(ii) To change tup_transformation(90, 103, 54, 45) into
tup_transformation(5, 45, 54, 90)
Answer:
(i) dictionary[tup[0]] = tup[1]
(ii) Tuples are immutable, so (90, 103, 54, 45) can’t be changed to (5, 45, 54, 90).
Question 23.
Write statements for the following:
(a) To check the existence of the value 56 in a list Lst
(b) To replicate the list L =[30, 40, 50] 4 times
Answer:
(a) 56 in Lst
(b) L*4
Question 24.
(I) Given a list L=[10, 9, 8, 7, 6]
(a) Write a statement to arrange the list in descending order and store to another list L1.
Or
(b) To display the lst three elements
(II) (a) Write a statement to reverse the list and store it in another list L1.
Or
(b) Write a statement to display the total number of elements in the list.
Answer:
(I) (a) L1=sorted(L,ascending=False)
Or
(b) print(L[0:3])
(II) (a) L1=L[:: -1]
Or
(b) print(len(L))
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.
Imagine a table Programmers with the following structure.
Write SQL commands for the following:
(i) Display the name of the programmer, which has the highest salary.
(ii) Update the salary of all programmer 2000, whose name start with the letter R.
Answer:
(i) Select P_Name from Programmers where SAL=(Select Max(Sal) from Programmers); (ii) Update Programmers set sal=sal +2000 where P_Name Like "R%";
Question 27.
(I) (a) Differentiate between the candidate key and the alternate key.
Or
(b) Consider the following table with their fields
Product(PID, Pname, Quality, Qty);
Write a command to remove the Primary key constraint from the PID column.
(II) (a) Write a relation between the candidate key, alternate key, and primary key.
Or
(b) Write a command to display each of the fields of a table “Automobile” with the type, size, and constraints.
Answer:
(I) (a) Candidate key: All columns of a relation that qualify for becoming primary key.
Alternate key: All candidate keys that are not primary keys.
Or
(b) Alter table Product Drop Primary key; (II) (a) Candidate key= Primary key + Alternate key Or (b) Describe Automobile:
Question 28.
(A) (i) Expand the following terms:
LAN, HTTP
(ii) What do you mean by 3G mobile technology?
Or
(B) (i) Can we use a URL to access a web page? How?
(ii) Name any two web browsers.
Answer:
(A) (i) LAN: Local Area Network
HTTP: HyperText Transfer Protocol
(ii) 3G is a short Term for the Third Generation of mobile telecommunication technology.
3G telecommunication networks support services that provide an information transfer rate of atleast 200 kbps.
Or
(B) (i) A URL is the canvas over an IP address where a website is stored. So a URL may also be used to access a web page.
(ii) Google Chrome, Internet Explorer
Section C
(3 × 3 = 9)
Question 29.
Write a Python program that reads the data from file ‘original.dat’ and deletes the line(s) having a word (passed as an argument). Then write these data after removing lines into the file ‘duplicate.dat’.
Or
Write a program in Python to open a text file “lines.txt” and display all those words whose length is greater than 5.
Answer:
import os def Delete (word): file1=open('original.dat', ‘rb’) nfile=open(‘duplicate.dat’, ‘wb’) while True: line=file1.readline() if not line: break else: if word in line: pass else: print(line) nfile.write(line) file1.close() nfile.close() Or f=open(“lines.txt”) data=f.read() str=data.split(' ') print("Words with length greater than 5") for w in str: if len(w)>5: print(w) f.close()
Question 30.
You have a stack of characters, where STACK is allocated N = 8 memory cells.
STACK: A, C, D, F, K,…,…,…
Describe the STACK at the end of the following operations. Here, Pop and Push are algorithms for deleting and adding an element to the stack.
(i) Pop (STACK, ITEM)
(ii) Pop (STACK, ITEM)
(iii) Push (STACK, L)
(iv) Push (STACK, P)
(v) Pop (STACK, ITEM)
(vi) Push (STACK, R)
(vii) Push (STACK, S)
(viii) Pop (STACK, ITEM)
Or
Write a Python program to input as many numbers and push them to a stack primestack[] using the function pushprimes(), only if the number input is a prime.
Answer:
The stack contents will be as follows after the operations of the stack:
(i) STACK: A, C, D, F (K is deleted)
(ii) STACK: A, C, D (F is deleted)
(iii) STACK: A, C, D, L (L is inserted)
(iv) STACK: A, C, D, L, P (P is inserted)
(v) STACK: A, C, D, L (P is deleted)
(vi) STACK: A, C, D, L, R (R is inserted)
(vii) STACK: A, C, D, L, R, S (S is inserted)
(viii) STACK: A, C, D, L, R (S is deleted)
Or
primestack =[] defpushprimes(n): c=0 for i in range(1, n+1): if n%i==0: c+=1 if c==2: primestack.append(n) ans='y' while ans=='y': n=input("Enter a number :") pushprimes(n) ans=input("Add more(y/n)")
Question 31.
(A) Write outputs for the SQL commands (i) to (iii) based on the table CUSTOMER given below:
(i) SELECT COUNT(*), GENDER FROM CUSTOMER GROUP BY GENDER; (ii) SELECT CNAME FROM CUSTOMER WHERE CNAME LIKE 'L%'; (iii) SELECT DISTINCT AREA FROM CUSTOMER;
Or
(B) (i) Change the width of the column CName to varchar(50).
(ii) Display names of Male customers from EAST.
(iii) Display in lowercase name and area of all customers.
Answer:
(A) (i)
(ii) No rows selected
(iii)
Or
(B) (i) ALTER TABLE Customer modify Cname varchar(50): (ii) Select CName from Customer where gender ="MALE" and Area="EAST"; (iii) Select Lcase(CName), Lcase(Area) from Customer:
Section D
(4 × 4 = 16)
Question 32.
(A) (i) Write the uses of try, except, else, and finally blocks in brief.
(ii) (a) This is the base class of all exceptions.
(b) A developer has not properly maintained the indentation in a program. Which exception will occur?
Or
(B) (I) How many except blocks can be written against a try block?
(II) What will happen if exception handling is not done in a program?
Answer:
(A) (i) Exception blocks
- try: Carrie’s code is expected to raise an exception.
- except: Carrie’s code to handle/respond against the exception.
- else: Carries code that executes if no exception occurs.
- finally: it Carries code that executes irrespective of whether an exception occurs or not.
(ii) (a) Exception class
(b) indentationError
Or
(B) (I) A try block can be written with multiple except blocks. Each except block can handle a specific type of exception condition and the corresponding code will execute if the exception occurs.
(II) If exception handling is not done in a code, the program may abnormally close leaving the user in a confusion.
Question 33.
Shubham is an employee of ABC company who works as a Python expert. For annual appraisal, he has created a CSV file named annual.csv, to store the tasks of employees in different projects. The structure of annual.csv is:
[emp_id, empName, project, duration]
For efficient data of employees, Shubham wants to write the following user-defined functions:
Accept() To accept the details of the employee and add them to the annual.csv
Show() To display the details of all employees.
Write the program in Python for the above information.
Answer:
import csv lst = ['EmpID', 'EmpName', 'Project', 'Duration'] def Accept(): f = open("annual.csv", "a", newline = '\n') wr = csv.writer(f.delimiter = "\t") lst = ['EmpID', 'EmpName', 'Project', 'Duration'] wr.writerow(lst) while True: ch = int(input("Enter 1 to add and 0 to exit")) if (ch == 1): emp_id = input("Enter employee id:") empName = input("Enter employee name:") project = input("Enter project name:") duration = int(input("Enter project completion duration in weeks:")) wr.writerow([emp_id, empName, project, duration]) elif ch==0: break f.close() def Show(): f1 = open("annual .csv",'r') data = csv.reader(f1) next(data) #skip the header row rw = 0 for i in data: rw = rw+1 print("Number of details:",rw) f1.close() Accept() Show()
Question 34.
Write the queries for questions (i) to (iv) based on the following tables SHOPPE and ACCESSORIES.
(i) To display Name and Price of all the ACCESSORIES in ascending order of their Price.
(ii) To display Id and SName of all SHOPPE located in Nehru Place.
(iii) To display Minimum and Maximum Price of each Name of ACCESSORIES.
(iv) To display the name and price of those ACCESSORIES whose id = “S01”
Or
To display the product-wise number of records.
Answer:
(i) SELECT Name, Price FROM ACCESSORIES ORDER BY Price; (ii) SELECT Id, SName FROM SHOPPE WHERE Area = ‘Nehru Place’; (iii) SELECT MIN(Price) “Minimum Price”, MAX(Price) "Maximum Price”, Name FROM ACCESSORIES GROUP BY Name; (iv) SELECT Name, Price FROM ACCESSORIES WHERE id = "S01"; Or SELECT Name, count(*) FROM ACCESSORIES GROUP BY Name;
Question 35.
Below is a table Item in the database Inventory.
Riya created this table but forgot to add the column ManufacturingDate. Can she add this column after the creation of the table?
Note the following to establish the connection between Python and MySQL:
Host: localhost
Username: system
Password: test
Database: Inventory
Answer:
Yes, she can add new column after creation of table.
import mysql.connector mycon = mysql.connector.connect(host = “localhost”, user = “system”, passwd = “test”, database = “Inventory”) cursor = mycon.cursor ( ) cursor.execute (“ALTER TABLE Item ADD ManufacturingDate Date NOT NULL”) cursor.close() mycon.close ()
Section E
(2 × 5 = 10)
Question 36.
Write a program code in Python to perform the following using two functions as follows:
addBook() To write to a CSV file “book.csv” file book no, book name, and no of pages with separator asa tab.
countRecords() To count and display the total number of records in the “book.csv” file.
Answer:
import csv def addBook(): f1 = open("book.csv", 'w', newline = "\n") w1 = csv.writer(f1, delimiter = "\t") w1.writerow(['BookNo', 'BookName', 'Pages']) while True: op = int(input("Enter 1 to add and 0 to exit")) if(op == 1); Bookno = int(input("Enter Book No:")) Bookname = input("Enter Book Name:") Pages = int(input("Enter Pages:")) w1.writerow([Bookno, Bookname, Pages]) elif op == 0: break f1.close() def countRecords(): f = open("book.csv","r") d = csv.reader(f) next(d) #to skip header row r = 0 for row in d: r = r+1 print("Number of records are", r) f.close() addBook() countRecords()
Question 37.
Trine Tech Corporation (TTC) is a professional consultancy company. The company is planning to set up its new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their requirement and suggest them the best available solutions. Their queries are mentioned as (i) to (v) below.
(i) Which will be the most appropriate block, where TTC should plan to install their server?
(ii) Draw a block-to-block cable layout to connect all the buildings most appropriately for efficient communication.
(iii) Suggest a suitable topology to connect the computers in each building.
(iv) Which of the following devices will be suggested by you to connect each computer in each of the buildings?
(a) Switch/Hub
(b) Modem
(c) Gateway
(v) The Company is planning to connect its offices in Hyderabad which is less than 1 km. Which type of network will be formed?
Answer:
(i) TTC should install its server in the finance block as it has a maximum number of computers.
(ii)
The above layout is based on the minimum cable length required.
(iii) Star topology, as it has independent connections that help easy network setup and fault detection.
(iv) (a) Switch/Hub: These are devices that can connect multiple nodes in a network.
(v) Since the distance is less than 1 km.
LAN (Local Area Network) will be formed.