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 allowed: 3 Hrs.
Max. Marks : 70
General Instructions:
- Please check this question paper contains 35 questions.
- The paper is divided into 4 Sections- A, B, C, D and E.
- Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
- Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
- Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
- Section D, consists of 3 questions (31 to 33). Each question carries 5 Marks.
- Section E, consists of 2 questions (34 to 35). Each question carries 4 Marks.
- All programming questions are to be answered using Python Language only.
Section-A
Question 1.
State True OR False : [1]
The keys of a dictionary can be a list.
(a) True
(b) False
Answer:
(b) False
Explanation:
Dictionary keys are immutable and lists are mutable data structures.
Question 2.
Foreign keys columns of linked tables must carry : [1]
(a) Integer values
(b) Character values
(c) Date type values
(d) Similar types of values in both the tables
Answer:
(d) Similar types of values in both the tables
Explanation:
Since a foreign key links tables, it must carry similar values in both the tables.
Question 3.
What will be the output of the following statement: [1]
12/4 + 121**0.5 + 32 %7
(a) 118.0
(b) 18.0
(c) 17.0
(d) 18.5
Answer:
(b) 18.0
Explanation:
The original expression is:
12/4 + 121**0.5 + 32 %7 = 3.0 + 11+4
= 18.0
Question 4.
What is the output of the following code: [1]
my_list=["Python", "Language"] print("-", join(my_list))
(a) Python- Language
(b) Python Language-
(c) -PYTHONLANGUAGE
(d) None of these
Answer:
(a) Python- Language
Explanation:
The join() function joins list elements with the delimiter specified.
Question 5.
Which of the following is not a DML command : [1]
(a) Describe
(b) Drop
(c) Delete
(d) Both (a) and (b)
Answer:
(d) Both (a) and (b)
Explanation:
Both describe and drop are DDL commands.
Question 6.
Which of the following topologies are best in terms of error detection [1]
(a) Star
(b) Bus
(c) Ring
(d) All are equally good
Answer:
(a) Star
Explanation:
Star topology has independent cables connecting the nodes. Hence error detection is easier.
Question 7.
What will be the output of the following code : [1]
S="AISSCE@2024" for a in S: if a.isdigit(): print(a)
(a)
2
0
2
4
(b)
2
4
0
2
(c) 0 2 4 2
(d) 4202
Answer:
(a)
2
0
2
4
Explanation:
The code checks for digits in the string and prints them.
Question 8.
Given: [1]
s="Lionistheking" s1="Parrotispretty" The expression: print(s[1:4].capitalize() + s1[1:7:2]) displays :
(a) ionart
(b) Ionart
(c) IONart
(d) None of these
Answer:
(b) Ionart
Explanation:
String[start:end:progression] extracts a substring from start to end -1 progressing with the progression specified.
Question 9.
Which of the following keywords are used to import modules : [1]
(a) import
(b) imports
(c) include
(d) inherits
Answer:
(a) import
Explanation:
Other keywords are inappropriate.
Question 10.
What are the possible outcome(s) after execution from the following code? Also, specify the maximum and the minimum value. [1]
import random PICK=random.randint(0, 3) CITY=["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"] : for I in CITY : for J in range (1, PICK): print(I, end= " ") print()
(a) DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA
(b) DELHI
DELHIMUMBAI
DELHIMUMBACHENNAI
(c) DELHI
MUMBAI
CHENNAI
(d) DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA
Answer:
Both (a) and (c) are possible options
Explanation:
PICK maxval = 3 minval = 0.
Question 11.
Which of the following is not a guided media? [1]
(a) Twisted pair
(b) OFC
(c) Telephone cable
(d) All are guided media
Answer:
(d) All are guided media
Explanation:
All the above media are wired media.
Question 12.
Given the following code that returns the sum of last digits of the arguments received . What should be filled in the missing blank for proper execution of the code. [1]
def sumdig(num1,num2,num3): #Function to return sum of last digits of the arguments
d=0 s=0 s=_______# Missing blank return s
(a) num1%10 + num2%10 + num3%10
(b) num1/10 + num2/10 + num3/10
(c) num1%10 + num2%10 + num3%10
(d) None of these
Answer:
(a) num1%10 + num2%10 + num3%10
Explanation:
%10 extracts the last digit from a number.
Question 13.
State True OR False : [1]
If a number is divided by 0 the ZeroDivideError occurs.
Answer:
False
Explanation:
Since a number is divided by 0 the ZeroDivisionError occurs.
Question 14.
An alternate key must carry: [1]
(a) Varchar type values
(b) Unique values
(c) Unique and non blank values
(d) All of these
Answer:
(c) Unique and non blank values
Explanation:
An alternate key may replace a primary key, so it must carry unique and non blank values.
Question 15.
The NIC of a computer is a: [1]
(a) Software (c) Has a permanent MAC address.
(b) Hardware (d) Both (b) and (c)
Answer:
(d) Both (b) and (c)
Explanation:
NIC stands for Network Interface Card. It is a hardware that has a permanent address called the MAC address.
Question 16.
The module to be imported for using the text file handling functions -read(),write() etc. is : [1]
(a) textmodule
(b) txtmodule
(c) operation module
(d) No module required
Answer:
(d) No module required
Explanation:
The text file handling functions do not require any module to be imported.
Q. 17 and 18 are Assertion and Reasoning 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 17.
Assertion (A): While opening a binary file the mode may not be specified. [1]
Reason (R): The open function for file opening by default takes the mode parameter as ‘rb’ for binary files, if no mode is specified.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Explanation:
For any types of files the default opening mode is taken as read mode if no mode is specified.
Question 18.
Assertion (A): A python function can return more than one value to the calling function. [1]
Reason (R): The return statement takes only a list as parameter.
Answer:
(b) Both A and R are true and R is not the correct explanation for A.
Explanation:
Python allows returning multiple values from a function by statements like : return a,b,c
Section-B
Question 19.
(i) Write the expanded names for the following abbreviated terms used in Networking and Communications:
(a) OFC
(b) HTML
(ii) What is domain name resolution? [2]
Answer:
(i) (a) OFC : Optical Fibre Cable
(b) HTML : Hypertext Markup Language
(ii) Obtaining the IP address of a web resource / web site from the domain name is called Domain name resolution.
Question 20.
Find the errors from the following code: [2]
c=dict() n-input(Enter total number) i=1 while i<=n: a=input("enter place") b=input("enter number") c[a]=b i=i+1 print("place", "\t", "number") for i in c : print(i, "\t", c[a[i]])
Answer:
c=dict() n=input("Enter total number") # Error 1 i=1 while i<=n: a=input("enter place") b=input("enter number") c[a]=b i=i+1 print("place", "\t", "number") for i in c : print(i, "\t", c[i])
Question 21.
Write a function Perfect(num) that accepts as parameter a number and returns. True if the number is a perfect number, else returns a False. [2]
(A perfect number is one which is the sum of its factors other than itself. Ex : 6=3+2+1)
OR
Write a void function that receives a 4 digit number and calculates the sum of squares of first two digits of the number and last two digits of the number e.g., if 1233 is passed as argument then function should calculate (12)2 + (33)2.
Answer:
def Perfect(num): s=0 for a in range(1,num): if num%a=0: s+=a if s==num: return True else: return False
OR
def void(x): returnint(x[:2])**2 + int(x(2:])**2 num=input("Enter the four digit number:-') print(void(num))
Question 22.
Write the output of the following Python code : [2]
def display(): a=[[[1,2,3,4,5],[6,7,8]],9] a[-1]=200 b=a[:] b[0][0][3]=17 print(a) print(b)
Answer:
[[[1, 2, 3,17, 5], [6, 7, 8]], 200]
[[[1, 2, 3,17, 5], [6, 7, 8]], 200]
Question 23.
Write the Python statement for each of the following tasks using BUILT-IN functions/methods only:
(i) Given empdict={“Eno”:123,”Ename”:”Jack”,”Sal”:78000}. To add a new key: value “Email”:”Jack@ gmail.com”
(ii) Given : t=(123,12,890,56,45) To display the last 3 elements of the tuple using negative indexes. [2]
Answer:
(i) empdict [“Email”]= [email protected]
(ii) print(t[-1:-4:-1])
Question 24.
(i) Sonal needs to display name of teachers, who have “O” as the third character in their name. She wrote the following query. [2]
SELECT NAME FROM TEACHER WHERE
NAME = “**O?”;
But the query isn’t producing the result. Identity the problem.
(ii) Then after write a query to change the width of the column NAME to varchar(40)
Answer:
(i) The wildcards are incorrect. The corrected query is SELECT name FROM teacher WHERE name LIKE’_ _O%’;
(ii) ALTER TABLE TEACHER MODIFY NAME varchar(40);
Question 25.
Identify the output of the following Python statements. [2]
L1, L2 = [10,15, 20, 25], [ ] for i in range(len(L1)): L2.insert(i,L1.pop()) print(L1, L2,sep="&")
Answer:
[ ] & [25, 20,15,10]
Section-C
Question 26.
Predict the output of the following code: [3]
def execute(x,y=200): temp=x+y print (temp,x,y) a,b=50,20 execute(b) execute(a,b) execute(b,a)
Answer:
220 20 200
70 50 20
70 20 50
Question 27.
Obtain the outputs of the following SQL queries based on the data given in the table PRODUCT. [3]
Table: PRODUCTS
PID | PNAME | QTY | PRICE | COMPANY | SUPCODE |
101 | DIGITAL CAMERA 14 X | 120 | 12000 | RENBIX | SOI |
102 | DIGITAL PAD lli | 100 | 22000 | DIGI POP | S02 |
104 | PEN DRIVE 16 GB | 500 | 1100 | STOREKING | SOI |
106 | LED SCREEN 32 | 70 | 28000 | DISPEXPERTS | S02 |
105 | CAR GPS SYSTEM | 60 | 12000 | MOVEON | S03 |
(i) SELECT MAX (PRICE), MIN (PRICE) FROM PRODUCTS;
(ii) SELECT PNAME FROM PRODUCTS WHERE PRICE = 12000;
(iii) SELECT DISTINCT SUPCODE FROM PRODUCTS;
Answer:
(i) MAX (PRICE) MIN (PRICE)
28000 1100
(ii) PNAME
DIGITAL CAMERA 14X CAR GPS SYSTEM
(iii) DISTINCT SUPCODE
S01
S02
S03
Question 28.
Write a function showords() to open a text file “words.txt” and display the words which have more than 5 letters.
OR
Write a function to count the number of lines in a text file “players.txt”. [3]
Answer:
def showords(): f=open( "words.txt") words=f.read() lines=words.split(' ') for wrd in lines: if len(wrd) > 5 : print(wrd) f.close()
OR
def countlines(): f=open("players.txt","r") lines=f.readlines() print("Number of lines :",len(lines))
Question 29.
Consider the table Employee given below : [3]
Table: EMPLOYEE
EMPID | NAME | DOB | DEPTID | DESIG | SALARY |
120 | Alisha | 23-Jan.-1978 | D001 | Manager | 75,000 |
123 | Nitin | 10-Oct.-1977 | D002 | AO | 59,000 |
129 | Navjot | 12-Jul.-1971 | D003 | Supervisor | 40,000 |
130 | Jimmy | 30-Dec.-1930 | D004 | Sales Rep. | |
131 | Faiz | 06-Apr.-1984 | D001 | Dep. Manager | 65,000 |
Based on the table write SQL queries for the following :
(i) To display the name of employees whose salary not known, in alphabetical order.
(ii) To display DEPTID from the table EMPLOYEE without repetition.
(iii) To modify the column Desig and change its width to varchar(25).
Answer:
(i) Select Name,SALARY fromEMPLOYEE where Salary IS NULL order by Name;
(ii) SELECT Distinct(DEPTID) from EMPLOYEE;
(iii) Alter table Employee MODIFY DESIG varchar(25);
Question 30.
A list contains following record of a customer: [3]
[Customer_name, Phone_number, City]
Write the following user defined functions to perform given operations on the stack named ‘status’:
(i) Push_element() – To Push an object containing name and Phone number of customers who live in Goa to the stack
(ii) Pop_element() – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack.
For example:
If the lists of customer details are:
[“Gurdas”, “99999999999”,”Goa”]
[“Julee”, “8888888888”,”Mumbai”]
[“Murugan”,”77777777777″,”Cochin”]
[“Ashmit”, “1010101010”,”Goa”]
The stack should contain:
[“Ashmit”, “1010101010”]
[“Gurdas”, “99999999999”]
What should be the output?
Answer:
[“Ashmit”,”1010101010″]
[“Gurdas”,”9999999999″]
Stack Empty
Section-D
Question 31.
ABC is professional consultancy company. The company is planning to set up their new offices in India with its hub at Bengaluru. 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. [5]
Physical locations of the blocks of ABC
Block to block distance (in metres)
Block (From) | Block (To) | Distance |
Human Resource | Conference | 110 |
Human Resource | Finance | 40 |
Conference | Finance | 80 |
Expected number of computers to be installed in each block
Block | Computer |
Human Resource | 25 |
Finance | 120 |
Conference | 90 |
(i) What will be the most appropriate block, where ABC should plan to install their server?
(ii) Draw a block diagram showing cable layout to connect all the buildings in the most appropriate manner for efficient communication.
(iii) What will be the best possible connectivity out of the following, you will suggest to connect the new setup of offices in Chennai with its London based office.
- Satellite link
- Infrared
- Ethernet cable
(iv) Which of the following device will be suggested by you to connect each computer in each of the buildings?
- Switch
- Modem
- Gateway
(v) The company 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
Answer:
(i) Finance block because it has maximum number of computers.
(ii)
(ii) Satellite link
(iii) Switch.
(iv) MAN (Metropolitan Area Network) as this network can be carried out in a city network.
Question 32.
(i) How is r+ file mode different from rb+ mode?
(ii) Given a binary file “Hospital.dat” storing details of patients as per following structure :
[patId, patname, gender, wardno, doctor]
Write a function transfer(wrd) to copy those records from the file to another file newfile.dat whose ward number is provided as parameter. [5]
OR
Given a binary file “Inventory.dat” storing details of stock as per following structure:
[ItemId, Iname, Qty, Reorder, Category]
Write a function Modify() to input an ItemId and update the item details in the file.
Answer:
(i) The r+ mode is used in text and csv files. The rb+ mode is used in binary files.
(ii) Program:
import pickle def transfer(wrd): newlist=[] f=open("Hospital.dat","r") f1=open("newfile.dat","w") try: while True: plist=pickle.load(f) for rec in plist: if rec[3]=wrd: newlist.append(rec) except: f.close() pickle.dump(newlist,f1) f1.dose()
OR
Program:
import pickle def Modify(ItemId): f=open("Inventory.dat","r") newrec=[] try: while True: Itlst=pickle.load(f) for rec in Itlst: if rec[0]= ItemId: in=input ("Enter New Item name :") iq= input ("Enter New quantity :") ro= input ("Enter Reorder :") ct= input ("Enter category :") newrec.append([in,iq,ro,ct]) else : newrec.append(rec) except: f.close() f=open( "In ventory.dat"," w") pickle.dump(newrec,f) f.close()
Question 33.
(i) Write the use of Group by clause of SQL
(ii) Write Python code to increase age of all employees by 1 year in the Employee table of database HTMdb with useridHRMan and password HRMANexe@pwd. [5]
Answer:
(i) The Group by clause is used to group records of a table on common values of a column to get aggregate results.
(ii)
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()
Section-E
Question 34.
Consider the following tables Mobilemaster and Mobilestock. [4]
Table: MOBILEMASTER
M_id | M_Company | M_Name | M_Price | M_Mf_Date |
MB001 | Samsung | Glaxy | 4500 | 2013-02-12 |
MB003 | Nokia | N1100 | 2250 | 2011-04-15 |
MB004 | Micromax | Unite3 | 4500 | 2016-10-17 |
MB005 | Sony | XperiaM | 7500 | 2017-11-20 |
MB006 | Oppo | Selfle Ex | 8500 | 2010-08-21 |
Table: MOBILESTOCK
S_id | M_id | M_Qty | M_Supplier |
S001 | MB004 | 450 | NEW Vision |
S002 | MB003 | 250 | Praveen Gallery |
S003 | MB001 | 300 | Classic Mobile Store |
S004 | MB006 | 150 | A_one Mobiles |
S005 | MB003 | 150 | The Mobile |
S006 | MB006 | 50 | Mobile Centre |
(i) Write the statement to decrease the price of all mobiles by 10%
(ii) To display the mobilename,company and corresponding supplier.
(iii) To display the Id, Manufacturing date and company of mobiles from Mobilemaster table which
have been manufactured after year “2015”
(iv) To display the maximum and minimum quantity from Mobilestock table.
Answer:
(i) Update mobilemaster set m_price=m_price -m_price*0.1;
(ii) Select m1.m_name,m1.m_company,m2.m_supplier from mobilemaster m1, mobilestock m2 where m1.m_id=m2.m_id;
(iii) Select m_id,m_mf_date,m_company from mobilemaster where year-(m_mf_date)>”2015-12-31″;
(iv) Select Max(m_qty), min(m_qty) from mobilestock;
Question 35.
Amritya Seth is a programmer, who has recently been given a task to write a python code to perform the
following binary file operations with the help of two user defined functions/modules:
(a) AddStudents() to create a binary file called STUDENT.DAT containing student information-roll number, name and marks (out of 100) of each student.
(b) GetStudents() to display the name and percentage of those students who have a percentage greater than 75. In case there is no student having percentage > 75 the function displays an appropriate message. The function should also display the average percent.
He has succeeded in writing partial code and has missed out certain statements, so he has left certain queries in comment lines. You as an expert of python have to provide the missing statements and other related queries based on the following code of Amritya. [4]
Answer:
import pickle def AddStudents(): ____ #1 statement to open the binary file to write data while True: Rno=int(input("Rno:")) Name=input("Name:") Percent=float(input("Percent:")) L=[Rno, Name, Percent] _____ #2 statement to write the list L into the file Choice=input("enter more(y/n):") if Choice in "nN": break F.close()
(b)
def GetStudents(): Total=0 Count rec=0 Count above 75=0 with open ("STUDENT.DAT", "rb") as F : while True: try: _____ #3 statement to read from the file Count rec+=1 Total+=R[2] if R[2]>75: print(R[1], "has percent=", R[2]) Count above 75+=l except: break if Count above 75=0: print("There is no student who has percentage more than 75") average=Total/Count rec print("average percent of class=", average) AddStudents() GetStudents()
(i) Which command is used to open the file “STUDENT.DAT” for writing only in binary format? (marked as # 1 in the Python code)
(ii) Which commands is used to write the list L into the binary file, STUDENT.DAT? (marked as #2 in the Python code)
(iii) Which command is used to read each record from the binary file STUDENT.DAT? (marked as #3 in the Python code)
(iv) What is r+mode of file opening?
Answer:
(i) F= open(“STUDENT.DAT”,’wb’).
(ii) pickle.dump(L,F)
(iii) R = pickle.load(F).
(iv) It opens a file for both reading and writing. The file pointer will be at the beginning of the file