sample paper CS
sample paper CS
COMPUTER SCIENCE
Class-12
SOLVED
Tme Allowed: 3 hours Maximum Marks: 70
General Instructions:
This question paper contains 37 questions.
Allquestions are compulsory. Howve, internal choices hane hen prowided in some questions. Atempt only one of the choices
in such questions
The aer is divided into 5 Sections- A, B, C, D and E
Sertion A consists of 21 questions (1 to 21). Each question carries 1 Mark.
Section Bconsists of 7 questions (22 to28). Each question carries 2 Marks.
Section C consists of 3questions (29 to 31). Each question carries 3 Marks.
Section Dconsists of 4 questions (32to 35). Each question carries 4 Marks.
Section Econsists of 2 questions (36 to 37). Each question carries 5 Marks.
All programming questions are to be answered using Python Language only.
" In case of MCQ text of the correct answer should also be Urtten.
Section-A
1. State True or False: [1]
The statement range (-1, -5) returns values -1, -2, -3 and 4.
2. ldentify the output of the following code snippet:
text = "Hello World! «
text = text.rstrip()
print (text + "Python")
(A) "Hello World! Python" (B) "Hello World!Python"
(C) "HelloWorld!Python" (D) "Hello World!Python" [1]
3. Which of the following expressions evaluates to True?
(A) (False) or (True and False) (B) (False and True) or not(False)
(C) (True and not(True)) or False (D) not(True or False) and True [1|
4. What will be the output of the expression?
word = abracadabra'
print (word. partition( a' )[: :-1])
(A) (bra', a', bracad') (B) (abr', a', 'cadabra' )
(C) ("bracadabra', a', ' ) (D) (bracad' , a', bra') [1]
5. What will be the output of the following code snippet? [1]
text = "WelcomeToPython"
print (text[ -11: -7])
0. Which output lines of the following program will print the same results?
tup1 = (10, 20, 30, 40, 50, 60, 70, 80, 90)
() print (tup1 [5 :-1]) (ii) print (tup1 [5 ])
(ii) print(tup1[5:]) (iv) print (tup1[-4:8])
(A) (1) and (ii) (B) ())and (iv)
() (ü) and (ii) (D) (), (ii) and (iv) [1]
1. Write the output of the code given below:
Y_dict = ("name"; "Aman", "age": 26}
Question Papers. COMPUTER
40 |
OSWAAL CBSE Sample
SCIENCE, Clas -2 sample Question Papers
17. Which protocolis used for remote login? |41
y_dict[´age') 27 (A)FTP (B) Telnet
ydict['addressl elhi" () HTTP
print(y_dict.itens()) ('address', "Delhi))) Which network device is uscd to
(D) IRCP 11|
(»age', 27), 'Delhi')) 18. Connect multiple network
(A) dict itees(i(name" 'AmYn'), ('age', 27), (´address', Delhi))
addresses? segments and make routing decisions based on |P
(8) dict keys([(nane', Aman' ), ('age', 27), ('address', (A) Hub (B) Switch
it_values([('name', 'Anan'), 19. Which network topology
() Router
(D) Repeater
(O connects all
(O) N th point-to-point connection to the hub? devices in a network to a central hub, where each device has a dediated
Nthon?
N i d e ) method do in speifhed index from the list.
S What dor the ntums the clement at the (Dirctioms: Q20 and Q2) Assertion(A) and Reason(R) based
and retum it. ouestions, Mart the currext choice as:
(A) Rem index but does not (A) Both Aand Rare true and Rjsis the correct
cement at the speohed
(8) Remv the
returns the lzs elernent of the list.
(B) Both
Aand R are truc and R not the
correct
explanation
for A
(9 ReNN and
the dement with the
pifed value from the list. R is False
(C) A is True but is True explanation
forA
(D) Rm later. What is the degree and iD) A0s False but R
9. Atable tuden has
I5 mumns and 100
ows 10 rows are added
110
cardinality tte 20. Assertion
(A): Afunction is a block of
organised and reusable code that
Labir nw7
(B) Degree: 15, Cardinality: is used to
perform a single, related
(A) Dege 5,Cardinality 110 (D) Degree: 150, Cardinality: 90 action.
() Degr 10, Cardinality acu): Function provides better modularity for your application and a high
degree code of
remove existing records from a table. reusability.
aunplete the following ode: 21. Assertion
(A): The DELETE command in SQL is used to |
10, Write the miing statement to Reason (R): The DELETE command can remove all records from a table if used
open ("example.txt", "r")
fle otherwise, it will only remove records that match the without a WHERE clause,
ata 6le.read (50) fle condition specified.
pointer to the end of the
t Move the hle
hle.write("New content added") Section-B
22. What distinguishes alist froma tuple in Python with respect to their characteristics?
fle.close()
True or False:
hantify data types that support element modification and that do not frum the following:
1l Sae whether the following slalement is list, tuple, set, dict
cexception, the else block will still be exealed
In ython orption handhng if an ccept blck catches an
12, Wht will te the output of the tollowing ode? 23. Give two examples of each of the following: 21
() Conditional statements
det displayString(): (ii) Iterative structures
p None
24. If LI = 15, 8, 3, 8,9, 8, 2] and L2 = [15, 25, 35], then
21
(Answer using built-in functions only)
"None à A Write a statenment to find the index of the first occurrence of 9 in L.
14 (p ): OR
print ("None 1s the same as o) (B) Write a statement to remove the first occurrence of 8from LI
el14 (p r)
print ("None 1s the Same as enpty string")
(ii) (A) Write a statement to extend LI by appending all elements of L2 to it.
OR
eli (p s) (B)) Write a statement to get a sorted list from L2 in descending order.
print ("None 1s the same as the string 'None")
lse:
25. What posible output(s) are expected to be displayed on screen at the time of euecution of the prngram from
print ("None of the above) the following code? Also, specify the minimum values that can be ansigned to each of the variables BECIN and
LAST.
lsplaystring()
(A) N r is thr air as 0 import random
(B) None is the sme as enmpty string.
() Nee the sanr as the string None (D) None of the above. VALUES = (10, 20, 30, 40, 50, 60, 70, 80]
13. Wh Q ammand is ud tu reove a BEGIN = random .randint (1, 3)
table from a dutabuse?
14. What w r the uutput d the Lquery? LAST random. randint (2, 4)
SAUCI cON() FROR orders ERE order for I in range (BEGIN, LAST+1):
A) he ountet d ede pland in the year 023 date 8E TWE EN 2023-01-01' AND 2023-12-31"; print (VALUES( I], end = ".")
(B) The ued valu ddets placrd un he yea (A) 3M40-50 (B) 10-20-30-40 (C) 30-4-S0-60 (D) 4OS0-17) 2
Ohe arbet der dste n dhe year 23
(D) he udet d unje den n ttei23 ASISh has written the folkowing code, but l am getting some errors whik evuing i. Rewnite it altet wmoving
year 23
all errors. Underline all the corrections made 21
15. wúh data type is tnN
pgrate lor stng a peron's phone number?
(B) OA(n) Value30
(0 TEXT for val in range (0,Value)
16. Cvna ckuswth (D) INT
he vet veed nul valus, wBuh sgyegate 1f val%A= =0
functon will ignore thee null values while cak
(A) s ) print (val°4)
(B) AVG)
(D) AVG() else 1f val%5-=0:
Question Papers,
oSWAAL CBSESample COMPUTER sample Question Papers
42 | | 43
print (val+3) elif string (-1] == 'b':
else string = string [:2]
print (val+10) an existing table. such as
21. () (A) What
SOL ommandis used
to modify the
structure of
adding oT Temosi else:
cOunt+= 1
oumns? OR break
a table?
a new record to print (string)
command is used to add (of type integer) to the
(6) What SQL
SOL ommandto add a
new field, Discount ITEM table. print (count)
() (A) Write an OR OR
table ITEM
column Qy from the Predict the output of the following code:
ommand to remove the
(B) Write an SOL numbers = [3, 6, 9, 12]
of mesh topology.
advantace and one disadvantage for num in numbers:
28. (A) Lis one OR
total = 0
HTTP?
HIIP. What is the use of
(B) Expand the term for i in range (num) :
Section-C if i % 2 == 0:
total += i
of "Me" or "My" words present in atext fle
Python that counts the number print (total, end=' )
29. (A) Write a function in
TXT
contents are as follows: Section-D
lí the "STORY.TXT
My first book 14)
32. (A) Consider the table Teacher given below:
was Me and Table: Teacher
My Familv. It
T ID NAME Age Department Date of join Salary Gender
gave me M
1 Arunan 34 Computer Sc. 2019-01-10 12000
hance to be
31 2017-03-24 20000 F
Known to the 2 Sanam History
32 Mathematics 2020-12-12 30000 M
worid. 3 Randeep
The orutput of the function should be: 2018-07-01 40000 F
4 Samira 35 History
Cunt of MeMy in file: 4 42 Mathematics 2021-09-05 25000 M
5 Raman
OR M
6 Shyam 50 History 2019-06-27 30000
(B) Write a function to count the number of lines starting with a digit in a text file "Diary.bxt". M
7 Shiv 44 Computer Sc. 2019-02-25 21000
30. (A) You have a stack named UndoStack that contains records of actions for undo functionality. Each atin Shalakha 33 Mathematics 2018-07-31 20000 F
recond is represented as a list containing action_type, timestamp and details.
Wite the following user-defined functions in Python to perform the specified operations on the stat Based on the table write SQL queries for the following:
UndoStak: (i) To display only names of teachers of "History" department.
(i) push _action(Undostack, new_action): This function takes the stack UndoStack and a new actin (ii) To display the name, age and department of teachers whose name has "a" as the 2nd letter.
fecord new_action as arguments and pushes the new action record onto the stack. (iüi) To increase the salary of Male teachers by 5% who are in "Computer Sc department.
a
(ü) pop_act ion(Urdostack): This function pops the topmost action record from the stack and retumi (iv) To retrieve the names and salaries of all teachers who belong to the 'Science' department and have
fthe stack is already empty, the function should display Underflow'. salary greater than 20,000.
(i) peek _oction(Undostack) : This function displays the topmost action record of the stack witu OR
debting it. lf the stack is empty, the function should display None'. (B) Write the output:
OR
(B) Wte the definition of a user-defined function push ) SELECT Department, AVG(Salary) AS Avg_Salary
Nand pushs all those integers which are odd from the odd(N), which accepts a list of integers in a Paau FROM Teacher
list N into a Stack named OddNumbers. GROUP BY Department;
i) Wite function pop_odd) to pop the (ii) SELECT NAME, Date of join
topmost
alresdy enpty, the function should display number rom the stack and return it. Ir e s FROM Teacher
(ü) Write functon Dsp odd() to 'Empty WHERE Age > = 35
display all elements of the stack without stad i
empty, the function should display
Eumpler if the 'None deleting them. If the ORDER BY Date of join DESC:
integers input into (i)) SELECT Gender, COUNT(") AS Number of Teachers
Ihen the stack
Odd'Numbers should the list VALUES
store: (15, 37. 591 are: (15, 22, 37, 44, 59) FROM Teacher
31. Predit the output of the GROUP BY Gender;
follwing code if the input is bccabc: Lowest Salary
string = input (iv) SELECT MAX(Salary) AS Highest_Salary, MIN(Salary) AS
Count = 3
("Enter a string:") FROM Teacher;
products sold in a store. Each record of the fle contains
while True: 23 Acsy Ale "ProductSales.csv" contains data on various [4
if string [0) s= 'a': the following data:
" Product ID
string = string (2:) " Product Name
OSWAAL CBSE Sample Question Papers, COMPUTER sumple Question Papers
44 | SOIENGE, Cas 12 Quantity - Anteger
|45
prlce float
" Tal Sales (Amount in dollas) 52500]
the fle may e: [P10T, Luptop', 35,
hr exampe, a sample rund o perform the seiid operations on this file: )
You are assigned to perfom the following tasks:
Write a function to add a new product record to the binary file. The function should take the product details
() Read
Vnte allthe dataNthon
the following functions
afrom the to display the rods for which the Quantity Sold is geater than s0
file and
records in the file. as arguments and append them to the file.
total saBes amount from all the (i) Write a function to update the quantity of a product in the file. The function should take Product ID and
(in) Calulate and ntum the
upcoming school board meeting He has
report for theinfomation the new quantity as arguments and update the record in the file.
34 Ritesh is tasked with prpaning a detailed
the databuse, which contain about students, teachers and actess to the (ii) greater
Write athan
function to read all product records from the binary file and display details of products wih aprice
chol and admin tabhks in
staft. Help him extract the following
SQL queries as
information by writing the desired
Table: School admbeinliosw.trative
mentioned For example:
50.