Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 10 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 10 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
“A tuple is an Editable data store”. [1]
Answer:
False
Question 2.
Which comments start with # symbol?
(a) Double line
(b) Multi-line
(c) Single line
(d) All of these
Answer:
(c) Single line
Question 3.
What is the output of the following code?
>>> a = 10
>>> b = 2
>>> print (“Output, is”, (a + 10 * 2 + b))
(a) Output is 22
(b) Output is 32
(c) Output is None
(d) None of these
Answer:
(b) Output is 32
Question 4.
Give the output for the following program segment given below.
for i in range (-5,-7,-1):
print (i + 1)
(a) -7,-6,-5
(b) -5,-6,-7
(c) No output
(d) Error
Answer:
(c) No output
Question 5.
Which index number is used to represent last character of string?
(a) – 1
(b) 1
(c) 0
(d) n – 1
Answer:
(a) -1
Question 6.
The ………. mode opens a file for both reading and writing. [1]
(a) wr
(b) rw
(c) r+
(d) a+
Answer:
(c) r+
Question 7.
Each key value pair in a dictionary is separated by a [1]
(a) :
(b) ;
(c) –
(d) =
Answer:
(a) :
Question 8.
A table needs to restrict Salary column values to more than 50000. The constraint that has to be used is [1]
(a) NULL
(b) PRIMARY KEY
(c) CHECK
(d) NOT NULL
Answer:
(c) CHECK
Question 9.
You can repeat the elements of the tuple using which operator? [1]
(a) *
(b) +
(c) **
(d) %
Answer:
(a) *
Question 10.
For readline(), a line is terminated by [1]
(a) ‘\n’
(b) EOF
(c) Either (a) or (b)
(d) None of these
Answer:
(c) Either (a) or (b)
Question 11.
Fill in the blank: A table can be sorted by fields. [1]
(a) 1
(b) 2
(c) More than 2
(d) None of these
Answer:
(c) More than 2
Question 12.
The join operation can join …….. tables. [1]
(a) 1
(b) 2
(c) 3
(d) Multiple
Answer:
(d) Multiple
Question 13.
State whether the following statement is True or False : A device that connects the network cable to the NIC is hub. [1]
Answer:
False
Question 14.
What will be the output of the following code? [1]
a, b = 10, 5
x, y = a + b, b – 2
z = x – y
print (“x:”, x, “y:”, y, “z:”, z)
(a) x: 16 y:3 z:20
(b) x: 15 y:3 z:20
(c) x: 16 y:3 z:12
(d) x: 15 y:3 z:12
Answer:
(d) x:15 y:3 z:12
Question 15.
Fill in the blank: In ……… card amount gets deducted from card’s bank account immediately. [1]
Answer:
Debit card
Question 16.
In which topology every node is connected to two other nodes? [1]
(a) Bus
(b) Mesh
(c) Star
(d) Ring
Answer:
(d) Ring
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) User-defined functions must stay in a Python module. [1]
Reason (R) Each user-defined function must stay in a module, which is linked to a folder where all the user defined functions of the module stay.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true but R is not the correct explanation for 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 for A.
Question 18.
Assertion (A) Python supports addition of data in file, preserving the previous data. [1]
Reason (R) The write mode erases all previous data of a pre-existing file.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true but R is not the correct explanation for 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 for A.
Section – B
Question 19.
(a) Mr. GopiNath Associate Manager of Unit Nations corporate recently discovered that the communication between his company’s accounts office and HR office is extremely slow and signals drop quite frequently. These offices are 120 metre away from each other and connected by an Ethernet cable. [1 + 1 = 2]
(i) Suggest him a device which can be installed in between the office for smooth communication.
(ii) What type of network is formed by having this kind of connectivity out of LAN, MAN and WAN?
(b) Expand the following ARPANET, WWW
Or
(a) Name the protocol, which helps you to communicate between a web server and web browser.
(b) Give one function of a gateway.
Answer:
(a) (i) The device that can be installed between the office for smooth communication is repeater.
(ii) The type of network is Local Area Network (LAN).
(b) ARPANET – Advanced Research Projects Agency Network WWW-World Wide Web
Or
(a) HTTP
(b) The gateway is a node in a network, which serves as a proxy server and a firewall system, that prevents the unauthorised access.
Question 20.
Write the corresponding Python expression for the following mathematical expression. [2]
(a) z = a/a+b-d2
(b) z = x2 + y3
Answer:
(a) z = a/(a+b) – (d*d)
(b) z = a/(x**2) + (y**d)
Question 21.
Determine which of the following identifiers are valid. If invalid, explain with reason. [2]
(i) name_1
(ii) _SUM
(iii) $sum
(iv) num ^ 2
Or
Find the output of the following code
i=1 while (i<5): print(i) i=i *2
Answer:
The valid identifiers are:
Identifier | Reason |
name_1 | Digits and underscore is allowed along with alphabets |
_SUM | Underscore at the first position is allowed |
The invalid identifiers are:
Identifier | Reason |
$sum | $ sign can be used in other programming languages for creating identifier, however Python does not support $ sign |
num^2 | Special character are not allowed |
Question 22.
Differentiate between char(n) and varchar(n) data types with respect to databases. [2] Or Write a output for following SQL queries, which are based on the table ITEMS. TABLE:ITEMS
(a) SELECT MAX(Price), MIN(Price) FROM ITEMS;
(b) SELECT Price * Qty AS AMOUNT FROM ITEMS WHERE Code=1004;
Answer:
Differences between char(n) and varchar(n) are as follows
char(n) | varchar(n) |
It stores a fixed length string between 0 and 255 characters. | It stores a variable length string. |
If the value is of smaller length, then it adds blank spaces. | No blanks are added by varchar(n) even if value is of smaller length. |
Some space is wasted in it. | No wastage of space in varchar(n). |
Or
(a)
MAX(Price) | MIN(Price) |
38000 | 1200 |
(b)
Amount |
107500 |
Question 23.
Find the output of the following program:
def calcresult ( ) : i = 9 while i > 1 : if (i% 2 = = 0): x = i%2 i = i - 1 else: i=i - 2 x = i print (x**2)
Answer:
Output
49
25
9
1
Question 24.
What is token? Name the tokens that are available in Python. [2]
Or
Find the syntax error in the following program and underline after correct them;
90 = w
while(w > 60)
print(w)
w = w – 50
Answer:
A smallest individual unit in a program is known as token. Python has the following tokens
- Identifiers
- Keywords
- Punctuators
- Literals
- Operators
Or
Correct code is
w = 90 while(w>60) : print(w) w = w - 50
Question 25.
Write a program to enter two numbers and print their difference. [2]
Answer:
a = int(input(”Enter first number :“)) b = int(input(”Enter second number :“)) Difference = a - b print (“Two numbers are :“ , a, b) print (“Difference is:”, Difference) Output Enter first number: 5 Enter second number: 3 Two numbers are : 5, 3 Difference is 2
Section – C
Question 26.
Consider the tables FAMILY and OCCUPATION: [1 × 3 = 3]
TABLE: FAMILY
Table: OCCUPATION
Write SQL queries for statements (a) to (c) based on tables FAMILY and OCCUPATION.
(a) To select all the information of family, whose Occupation is Service.
(b) To list the name of family, where female members are more than 3.
(c) To list all names of family with income in ascending order.
Answer:
(a) SELECT * FROM FAMILY F, OCCUPATION O WHERE F.OccupationId=O.OccupationId AND Type = ‘Service’;
(b) SELECT Name FROM FAMILY WHERE FemaleMembers > 3;
(c) SELECT Name, Income FROM FAMILY ORDER BY Income;
Question 27.
Write a method countFile() to count and display the number of lines starting with the word ‘FILE’(including small cases and upper cases) present in a text file “start, txt”. [3]
e.g. If the file “start.txt” contains the following lines:
Get the data value to be deleted,
Open the file for reading from it.
Read the complete file into a list
Delete the data from the list
Open the file
Open same file for writing into it
Write the modified list into file.
Close the file.
The method should display
Total lines started with word ‘FILE’ is/are: 0
Or
Write definition of a function that takes input a sentence and display the list of words that end with a lowercase vowel and list of words that end with a lowercase consonant
Answer:
import os def countFile( ): if os.path.isfile(”start.txt”): f=open( ‘start. txt”, “r”) c=0 print( “The lines are: “) while True: l=f.readline() l=l.rstrip() print (l) if not l: break list1=l.upper( ).split( ) if(list1[0]==’ FILE’): c=c+1 if(c>0): print(”Total lines started with the word ‘FILE’ is/are:”,c) else: print(”There is no line started with the word ‘FILE’ ") f.close() else: print(”File does not exist’)
Or
def vowelconsonant(sen): vowel=[] consona nt=[] for w in sen.split(' '): if w[-1] not in 'aeiou' : consonant.append(w) elif w[-1] in 'aeiou' : vowel.append(w) print("List of words ending with vowels", vowel) print("List of words ending with consonants ", consonant)
Question 28.
Study the following tables DOCTOR and SALARY and write SQL commands for the questions (a) to (c). [1 × 3 = 3]
TABLE: DOCTOR
TABLE: SALARY
(a) Display NAME of all doctors who are in MEDICINE department having more than 10yrs experience from the table DOCTOR.
(b) Display the average salary of all doctors working in ENT department using the tables DOCTOR and SALARY. SALARY = BASIC + ALLOWANCE.
(c) Display the minimum ALLOWANCE of female doctors.
Answer:
(a) SELECT NAME FROM DOCTOR WHERE DEPT = ‘MEDICINE’ AND EXPERIENCE > 10;
(b) SELECT AVG(BASIC + ALLOWANCE) FROM SALARY WHERE SALARY.ID INC SELECT ID FROM DOCTOR WHERE DEPT = ‘ENT’);
(C) SELECT MIN(ALLOWANCE) FROM SALARY WHERE SALARY.ID IN(SELECT ID FROM DOCTOR WHERE SEX = ‘F’);
Question 29.
Write a program to count the frequency of elements in a list entered by user. [3]
Answer:
a = [] n = int(input(“Enter number of elements:”)) for i in ranged (1, n + 1): b = int(input(“Enter element:”)) a.append (b) k = 0 num = int(input(“Enter the number to be counted:”)) for j in a : if (j == num): k = k + 1 print ("Number”, num, "is appear”, k, “times.”)
Question 30.
Write the Push operation of stack containing person names. Notice that the name should only accept characters, spaces and period (.) except digits. Assume that Pname is a class instance attribute. [3]
Answer:
def insert( ): name_pattern = re.compile (r “[A-Za-zs.]”) while True : n = input (“Enter name:”) while name_pattern. search (n) : print ("Invalid name”) print ("Enter name correctly”) n = input( ) Sname. append (n) c = input (“Enter more name <y/n>”).upper ( ) if (c! = ‘y'): break insert()
Section – D
Question 31.
Consider the following table FLIGHTS :
TABLE: FLIGHTS
Which functions will be used to : [1 × 4 = 4]
(a) Display total number of flights.
(b) Display number of flights whose FL_NO starts with “IC”
(c) Show the average Number of stops.
(d) Show the maximum number of stops.
Answer:
(a) SUM()
(b) COUNT()
(c) AVG()
(d) MAX()
Question 32.
Create a binary file student.dat to hold students’ records like Rollno., Students name, and Address using the list. Write functions to write data, read them, and print on the screen. [4]
Give two functions as shown below:
file_create() To write data into the file.
read_read() To read data and print from file.
Answer:
import pickle rec=[] def file_create(): f=open("student.dat”,"wb”) rno = int(input("Enter Student No:")) sname = input("Enter Student Name:") address = input("Enter Address:”) rec=[rno,sname,address] pickle.dump(rec, f) def read_read(): f = open("student.dat","rb") print("*"*78) print("Data stored in File....") rec=pickle.load(f) for i in rec: print(i) file_create( ) read_data( )
Section – E
Question 33.
Workalot consultants are setting up a secured network for their office campus of Gurgaon for their day-to-day office and web based activities. They are planning to have connectivity between 3 buildings and the head office situated in Mumbai.
Answer the questions (a) to (e) after going through the building positions in the campus and other details, which are given below: [1 × 5 = 5]
(a) Suggest the most suitable place (i.e. building) to house the server of this organisation. Also, give a reason to justify your suggested location.
(b) Suggest a cable layout of connections between the buildings inside the campus.
(c) Suggest the placement of the following devices with justification :
(i) Switch
(ii) Repeater
(d) Write the use of Modem in a network.
(e) What is the use of firewall in network?
Answer:
(a) Building RED is the suitable place to house the server because it has maximum number of computers.
(b)
(c) (i) Switches are needed in every building as they help share bandwidth in every building.
(ii) Repeaters may be skipped as per above layout (because distance is less than 100 m), however if building GREEN and building RED are directly connected, we can place a repeater there as the distance between these two buildings is more than 100 m.
(d) A Modem is a network device that converts Analog signals to Digital and Digital to Analog.
(e) Firewall prevents the unauthorised access in the network.
Question 34.
(a) Write the syntax of ORDER BY clause. [1 + 4 = 5]
(b) Consider the table MobileStock with following fields
M_Id, M_Name, M_Qty, M_Supplier
Write the Python code to fetch all records from database Mobile.
Or
(a) What are DML?
(b) Consider the following table Traders with following fields
Write Python code to display the names of those traders who are either from Delhi or from Mumbai.
Answer:
(a) Syntax
SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC/DESC;
(b)
import mysql.connector as mydb mycon = mydb.connect (host = “local host”, user = “root”, passwd = “system”, database = “Mobile”) cursor = mycon.cursor ( ) sql = “SELECT*FR0M MobileStock” ; try: cursor. execute (sql) display = cursor. fetchall ( ) for i in display: print (i) except : mycon.roll back ( ) mycon.close ( )
Or
(a) DML (Data Manipulation Language) is a part of SQL, which provides commands for inserting, deleting and updating the information in a database. Different DML commands are SELECT UPDATE, INSERT.
(b)
import mysql.connector mycon = mysql.connector.connect (host = “localhost”, user = “root”, passwd = “system”, database = “Admin”) cursor = mycon. cursor ( ) sql = “SELECT * FROM Traders WHERE City = ‘Mumbai’ OR City = ‘Delhi’” try: cursor.execute(sql) dis = cursor.fetchall ( ) for i in disp: print (i) except : mycon.rollback ( ) mycon.close ( )
Question 35.
(a) What is difference between tell() and seek() methods? [2 + 3 = 5]
(b) A Binary file “lottery.dat” stores details of lottery ticket holders. The file stores the following details :
TicketNo State Type Prizemoney
Write a program using two functions to operate the file data.
AddBuyers(State) To accept more ticket details and store them into the file only if the ticket is not from state passed as parameter to the function.
TicketSearch(tid) To open the file “lottery.dat” and display details of the ticket whose id is supplied as the parameter to the function.
Or
(a) Compare text files and binary files.
(b) A Binary file “car.dat” stores details of cars. The file stores the following details :
CarNo Brand Kms Cost
Write a program using two functions to operate the file data.
AddCardata() To accept car details and store them into the file “car.dat”
CarReport() To open the file “car.dat” and display details of the cars who have run more than 100000 kilometres.
Answer:
(a) tell() method returns the current position of cursor in file while seek() method changes the cursor position by bytes as specified by the offset.
(b)
import pickle def AddBuyers(State) : f=open("lottery.dat ","ab") ans='y' tid=" " st=" ’’ type=" " pmoney=0 . 0 while ans=='y': tid=input("Enter ticket id”) st=input("Enter state name ’’) type=input("Enter.ticket type : ") pmoney=float(input(“Enter prizemoney “)) tlst=[tid, st, type, pmoney] if st==State: pickle.dump(tlst, f) ans=input("Continue(y/n)") f.close( ) def TicketSearch(tid): f=open("lottery.dot",”rb”) while True: try: tlst=pickle.load(f) if tlst[0]==tid: print(tlst) break except EOFError: print(“No such ticket!!!”) f .close() AddBuyers(State) TicketSearch(tid)
Or
(a)
(b)
import pickle def AddCarclata() : f=open("car.dat”, “wb") ans=’y’ cno=" " bd=" " kms=0.0 cost=0.0 while ans==’y’: cno=input(”Enter car number :") bd=input("Enter brand name :") kms=float(input(”Enter kilometers : “)) cost=float(input("Enter cost : ")) clst=[cno, bd, kms ,cost] pickle.dump(clst , f) ans=input( “Continue(y/n)”) f.close( ) def CarReport( ): f=open("car.dat ", ”rb”) while True: try: clst=pickle.load(f) if int(tlst[2] > 100000): print(clst) break except EOFError: print(”No such ticket!!!”) f.close( ) AddCardata( ) CarReport( )