12th Updated

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

CBSE - XII - R1 CS

REVISION TEST - 1
Standard - XII
COMPUTER SCIENCE
Time allowed : 3 hours Maximum Marks : 80
• 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 2 questions (31 to 32). Each question carries 4 Marks.
• Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.

Q. No Question Marks

SECTION A

State True or False


1. 1
“Dictionaries in python are mutable.”

Which of the following is an invalid identifier


2. 1
a) myname b) p9tv c) def d) _new 1

Which one of the following is the function to get list of keys from a dictionary dict in
python?
a. dict.getkeys()
3. 1
b. dict.getvalues()
c. dict.keys()
d. None Of These

Consider the given expression:


True or not False and True
Which of the following will be correct output if the given expression is evaluated?
1
4. a. True
b. False
c. NONE
d. NULL

What will be the output of the following code:


t=(4,5,6)
t1=t*2
print(t1) 1
5.
a) (4,5,6,4,5,6)
b) (4,4,5,5,6,6)
c) (8,10,12)
d) None of the above
CBSE - XII - R1 2 CS
Select the correct output of the code :
S= “Amrit Mahotsav @ 75”
a=S.partition (“ “)
6. 1
print (a)
(a) ( ‘Amrit Mahotsav’, ‘@’, ‘75’) (b) [‘Amrit’, ‘Mahotsav’, ‘@’, ‘75’]
(c) (‘Amrit’, ‘Mahotsav @ 75’) (d) (‘Amrit’, ‘ ‘, ‘Mahotsav @ 75’)

Given the following dictionary


Day={1:”Monday”, 2: “Tuesday”, 3: “Wednesday”}
Which statement will return “Tuesday”.
7. (a) Day.pop() 1
(b) Day.pop(2)
(c) Day.pop(1)
(d) Day.pop(“Tuesday”)

What will the following expression be evaluated to in Python ?


2+3/3**1**2*5+10
(a) 6.5
8. 1
(b) 17.0
(c) 16.0
(d) 17 1

Which of the following statement(s) would give an error after executing the following code?
Stud = {“Murugan”:100,”Mithu”:95 } # Statement 1
print (Stud[95]) # Statement 2
Stud [“Murugan”]=99 # Statement 3
print (Stud.pop()) # Statement 4
9.` 1
print (Stud) # Statement 5
a) Statement 2
(b) Statement 3
c) Statement 4
(d) Statements 2 and 4

10. 1

What possible output(s) are expected to be displayed on screen at the time of execution of
the following code ?
CBSE - XII - R1 3 CS

Options :

a) Pencil:Book
b) Pencil:Book
Eraser:Bag
c) Pen:Book
Bag:Book
d) Bag:Eraser
Consider the code given below:
c=1
def add():
# missing statement
c=c+4
print(c)
add()
11. 1
Which of the following statements should be given in the blank for #Missing Statement, if
the output produced is 5 ?
Options:
a. global c
b. global c= 5
c. global 5
d. c= 5 1

State whether the following statement is True or False:


12. 1
An exception may be raised even if the program is syntactically correct.

Observe the following code and answer the questions that


1
13. follow:
File=open (“Mydata”, ”a”)
_____________________ #Blank1
File.close()
i) What type of file is Mydata?
ii) Fill the Blank1 with statement to write “ABC” in the file
“Mydata”
CBSE - XII - R1 4 CS

14. 1

a) MyCompany/Transactions.Dat
b) MyCompany/Accounts/Transactions.Dat
c) Accounts/Transactions.Dat
d) ../Transactions.Dat

Which of the following methods will give the current position of the file pointer?
15. 1
(a)seek() (b)tell() (c)getloc() (d) None of the above

Consider the operations done on stack :


push(50)
push(80)
pop
16. 1
push(20)
push(50)
pop
pop
pop
push(158.96)
push(57.8)
After the completion of all operation, the number of elements present in stack
are:___________

Q17 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

Assertion (A): Exception handling code is separate from normal code.


Reasoning (R) : Program logic is different while exception handling code uses specific
17. 1
keywords to handle exceptions.
CBSE - XII - R1 5 CS
Assertion (A) : readlines() reads all the lines from a text file and returns the lines along with
newline as a list of strings.
18. 1
Reason (R) : readline() can read the entire text file line by line without using any looping
statements.

SECTION B

Rahul has written a code to input a number and return its reverse. His code is having
errors. Rewrite the correct code and underline the corrections made.

def reverse()
n=int(input(“Enter number :: “)
19. rev=0 2
while(num>0)
r=num%10
rev=rev*10+r
num=num//10
return rev

Write a function countNow(PLACES) which takes a list of names and displays the names
(in uppercase) of the places whose names are longer than 5 characters.
For example, Consider the following List
PLACES= [“Delhi”,”London”,”Paris”,”New York”,”Doha”]
The output should be:
LONDON
20. NEW YORK 2
OR
Write a function, lenWords(STRING), that takes a string as an argument and returns a
tuple containing length of each word of a string.
For example, if the string is “Come let us have some fun”, the tuple will have (4, 3, 2, 4, 4,
3)
PLACES= [“Delhi”,”London”,”Paris”,”New York”,”Doha”]

What possible outputs are expected to be displayed on screen at the time of


execution of the program from the following code? Also specify the
maximum value that can be assigned to each of the variables L and U.
import random
21. 2
Arr=[10,30,40,50,70,90,100]
L=random.randrange(1,3)
U=random.randrange(3,6)
for i in range(L,U+1):
print(Arr[i],"@",end="")
(i) 40 @50 @
(ii) 10 @50 @70 @90 @
(iii) 40 @50 @70 @90 @
CBSE - XII - R1 6 CS
(iv) 40 @100 @

Write the output for the following python code:


def Change_text(Text):
T=""
22. for K in range(len(Text)): 2
if Text[K].isupper():
T=T+Text[K].lower();
elif K%2==0:
T=T+Text[K].upper()
else:
T=T+T[K-1]
print(T)
Text="Good go Head"
Change_text(Text)
23 Differentiate text and CSV files
1+1=2
24. Brief Stack operations in Python using list.
2

a) PREDICT THE OUTPUT


t1=("Bangalore",[1,2,'3'],'S',(3,4,6),"Centre",10)
print(t1[-2:]+t1[3])
b) What will be the output of following program:
my_dict = {}
25. my_dict[1] = 1 2
my_dict['1'] = 2
my_dict[1.0] = 4
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)

SECTION C

Write a function EVEN_LIST(L), where L is the list of elements passed


as argument to the function. The function returns another list named ‘evenlist’
26. that stores even numbers in the list. For example: 3
If L contains [1,2,3,4,5,6,7,8]
The evenlist will have - [2,4,6,8]
CBSE - XII - R1 7 CS
Write the output of the code given below:
a=30
def call(x):
global a
if a%2==0:
x+=a
27. 1*3=3
else:
x - =a
return x
x=20
print(call(35),end=”#”)
print(call(40),end=”@”)

Write a function count_Dwords () in Python to count the words ending with a digit in a
text file “details.txt”.

Example:
If the file content is as follows:
On seat2 VIP1 will sit and
On seat1 VVIP2 will be sitting
Output will be:
Number of words ending with a digit are 4

OR
Write the definition of a Python function named LongLines ( ) which reads the contents 3
of a text file named ‘lines.txt’ and displays those lines from the file which have at least 10
words in it. For example, if the content of ‘lines.txt’ is as follows:
Once upon a time, there was a woodcutter
He lived in a little house in a beautiful, green wood.
One day, he was merrily choping some wood.
He saw a little girl skipping through the woods, whistling happily.
The girl was followed by a big gray wolf.
28.
Then the function should display output as:
He lived in a little house in a beautiful, green wood.
He saw a little girl skipping through the woods, whistling happily
CBSE - XII - R1 8 CS
A list contains following record of course details for a University:
[Course_name, Fees, Duration]
Write the following user defined functions to perform given operations on the stack named
‘Univ’ :
(i) Push_element() - To push an object containing the
Course_name, Fees and Duration of a course, which has fees
greater than 100000 to the stack.
(ii) Pop_element() - To pop the object from the stack and display it.
29. Also, display “Underflow” when there is no element in the stack. 1*3=3
For example :
If the lists of courses details are :
[‘MCA’, 200000,3]
[‘MBA’, 500000,2]
[‘BA’, 100000, 3]
The stack should contain :
[‘MBA’, 500000,2]
[‘MCA’, 200000,3]

A list contains following record of a student: [student_name, age, hostel]

Write the following user defined functions to perform given operations on the stack named
‘stud_details’:
• Push_element() - To Push an object containing name
and age of students who live in hostel “Ganga” to the stack
• 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: 3

[“Barsat”,17,”Ganga”]
[“Ruben”, 16,”Kaveri”]
[“Rupesh”,19,”Yamuna”]
The stack should contain
[“Barsat”,17,”Ganga”]
The output should be:
30.
[“Barsat”,17,”Ganga”]
Stack Empty
SECTION D
Write a function AMCount() in Python, which should read each character of a text file
STORY.TXT, should count and display the occurrence of alphabets A and M (including
small cases a and m too).
For Example:
31 If the file content is as follows: 4
As simplified by official websites.
The EUCount() function should display the output as:
A or a:4
M or m :2
CBSE - XII - R1 9 CS
i. Differentiate w and a in python
32. ii. Write a function display_words() in python to read lines from a text file “story.txt”, and 1+3
display those words, which are less than 4 characters.

SECTION E

What is a csv file?


Write a Program in Python that defines and calls the following user defined functions:
• INSERT() – To accept and add data of a student to a CSV file ‘student.csv’. Each
33. record consists of a list with field elements as sid, name and marksto store student id,
1+4
name and marks respectively.
• COUNTSTUDENTS() – To count the number of records present in theCSV file
named‘student.csv’.
OR

What is the purpose of delimiter?


Write a Program in Python that defines and calls the following user defined functions:
add() – To accept and add data of a product to a CSV file ‘product.csv’. Each record con-
sists of a list with elements as pid, pnameand priceto storeproduct id, product name and
pricerespectively.
search()- To display the records of the products whose price is more than5000.

Explain the following predefined exceptions along with an example.


34. 5
i) KeyError ii) IndexError iii) IOError

iv) AttributeError v) ValueError

Shreyas is a programmer, who has recently been given a task to write a user defined
function named write_bin() to create a binary file called Cust_file.dat containing customer
information – customer number (c_no), name (c_name), quantity (qty), price (price) and
35. amount (amt) of each customer. 5
The function accepts customer number, name, quantity and price. Thereafter, it displays the
message ‘Quantity less than 10 ….. Cannot SAVE’, if quantity entered is less than 10.
Otherwise the function calculates amount as price * quantity and then writes the record in
the form of a list into the binary file.
CBSE - XII - R1 1 CS
0

i) Write the correct statement to open a file 'Cust_file.dat' for writing the data of the
customer.
ii) Which statement should Shreyas fill in Statement 2 to check whether quantity is less than
10.
iii) Which statement should Shreyas fill in Statement 3 to write data to the binary file and in
Statement 4 to stop further processing if the user does not wish to enter more records.
OR
(Option only for part (iii))
iii) What should Shreyas fill in Statement 5 to close the binary file named Cust_file.dat
and in Statement 6 to call a function to write data in binary file?

You might also like