XII CS Sample Paper-II
XII CS Sample Paper-II
Q1. What is the output of the following Python Code, Select any one of the following
options? (1)
import random
print(int(random.random()*5))
i. Always generate 0
ii. Generate any number between 0 to 4 (including both)
iii. Generate any number between 0 to 5 (including both)
Q3. Identify the correct option to print the value 80 from the list (1)
L=[10,20,40,80,20,5,55]
(i) L[80] (ii) L[4] (iii) L[L] (iv) L[3]
Q4.. Identify the correct output of the following python code: (3)
def display(s):
l = len(s)
m=" "
for i in range(0,l):
if s[i].isupper():
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
elif s[i].isdigit():
m=m+"$"
else:
m=m+"*"
print(m)
display("EXAM20$$21")
i) ii)
e E
eX Ex
eXa Exa
eXam Exam
eXam$ Exam$
eXam$$ Exam$$
eXam$$* Exam$$$*
eXam$$** Exam$$**
eXam$$**$ Exam$$**$
eXam$$**$$ Exam$$**$$
iii) iv)
e E
ex EX
exa EXA
exam EXAM$$
exam$
exam$$
exam$$*
exam$$**
exam$$**$
exam$$**$$
Q5. Krishnav is looking for his dream job but has some restrictions. He loves Delhi
and would take a job there if he is paid over Rs.40,000 a month. He hates Chennai and
demands at least Rs. 1,00,000 to work there. In any another location he is willing to work for
Rs. 60,000 a month. The following code shows his basic strategy for evaluating a job offer.
(5)
Code:
pay= _________
location= _________
if location == "Mumbai":
print ("I’ll take it!") #Statement 1
elif location == "Chennai":
if pay < 100000:
print ("No way") #Statement 2
else:
print("I am willing!") #Statement 3
elif location == "Delhi" and pay > 40000:
print("I am happy to join") #Statement 4
elif pay > 60000:
print("I accept the offer") #Statement 5
else:
print("No thanks, I can find something better")#Statement 6
On the basis of the above code, choose the right statement which will be executed when
different inputs for pay and location are given.
Input: location = "Chennai”, pay = 50000
a. Statement 1
b. Statement 2
c. Statement 3
d. Statement 4
Q6. Consider the following code and answer the questions that follow:
Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}
Library ={'5':'Madras Diaries','6':'Malgudi Days'}
i. Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime
Thriller’. He has written the following command:
Book[‘Crime’]=’Crime Thriller’
But he is not getting the answer. Help him choose the correct command: (1)
a. Book[2]=’Crime Thriller’
b. Book[3]=’Crime Thriller’
c. Book[2]=(’Crime Thriller’)
d. Book[3] =(‘Crime Thriller’)
ii. The command to merge the dictionary Book with Library the command would
be: (1)
a. d=Book+Library
b. print(Book+Library)
c. Book.update(Library)
d. Library.update(Book)
iv. In order to check whether the key 2 is present in the dictionary Book, Ramesh
uses the following command: (2)
2 in Book
He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’
exists in the dictionary Library, he uses the following command:
‘Madras Diaries’ in Library
But he gets the answer as ‘False’. Select the correct reason for this:
a. We cannot use the in function with values. It can be used with keys only.
b. We must use the function Library.values() along with the in operator
c. We can use the Library.items() function instead of the in operator
d. Both b and c above are correct.
Q7 . With reference to the above declared dictionaries, predict the output of the
following code fragments (3)
Code1. Code2
Q8. Priyank is a software developer with a reputed firm. He has been given the task
to computerise the operations for which he is developing a form which will
accept customer data as follows:
i. The data to be entered is : (1)
a. Name
b. Age
c. Items bought( all the items that the customer bought)
d. Bill amount
ii. Choose the most appropriate data type to store the above information in the given
sequence: (2)
a. string, tuple, float, integer
b. string, integer, dictionary, float
c. string, integer, integer, float
d. string, integer, list, float
iii. Now the data of each customer needs to be organised such that the customer can be
identified by name followed by the age, item list and bill amount. Choose the appropriate
data type that will help Priyank accomplish this task. (1)
a. List
b. Dictionary
c. Nested Dictionary
d. Tuple
iv. Which of the following is the correct way of storing information of customers named
‘Paritosh’ and ‘Bhavesh’ with respect to the option chosen above? (2)
iv. In order to calculate the total bill amount for 15 customers, Priyank (1)
Statement 1. must use a variable of the type float to store the sum.
Statement 2. may use a loop to iterate over the values
a. Both statements are correct.
b. Statement 1 is correct, but statement 2 is not.
c. Both statements ar incorrect.
d. Statement 1 is incorrect but statement 2 is correct.
Q9.Your teacher has given you a method/function FilterWords() in python which
read lines from a text file NewsLetter.TXT, and display those words, which are
lesser than 4 characters. Your teachers intentionally kept few blanks in between
the code and asked you to fill the blanks so that the code will run to find desired
result. Do the needful with the following python code. (5)
def FilterWords():
c=0
file=open('NewsLetter.TXT', '_____') #Statement-1
line = file._____ #Statement-2
word = _____ #Statement-3
for c in word:
if _____: #Statement-4
print(c)
_________ #Statement-5
FilterWords()
i. Write mode of opening the file in statement-1?
a. a
b. ab
c. w
d. r
ii. Fill in the blank in statement-2 to read the data from the file.
a. File.Read()
b. file.read()
c. read.lines( )
d. readlines( )
iv. Fill in the blank in statement-4, which display the word having lesser than 4
characters.
a. len(c) ==4
b. len(c)<4
c. len ( )= =3
d. len ( )==3
Q13. Identify the correct option to add new value 50 to existing tuple T (1)
T = (11,22,33,44,55)
(i) T = T + 66 (ii) T = T + 66 (iii) T = T + (66,) (iv) T = T + (66)
Q15. Which is the output of the following python code. Write reason also: (2)
d={}
d[100]=100
d['200']=200
d[100.0]=50
sum=0
print(d)
for i in d:
sum+=d[i]
print(sum)
i) {50:100,’200’:’200} 250
ii) {100:100,50:100}
250
iii) {100: 50, '200': 200}
250
Q16. What is the minimum and maximum value of 'A' in the following statement. (1)
import random
A=random.randint(2,30)
print(A)
i)3 and 30
ii)2 and 30
iii)2 and 29
Q17.Ramesh is writing a program to find the factorial of a number. Help him to complete the
program by selecting the correct code :- (4)
num=5
while________ #second statement
Q18.Rohan wants to drive a car but He is unable to drive because his age is below 18.A
python code is written to check his age .identify it is correct or incorrect and write reasons:
(2)
Age=input(“enter age:”)
if age<=18:
print(“you are not eligible””)
a)Correct b)Incorrect
Q19.Ravi wants to add new student’s record ,Identify the name of function to add new
record: (1)
i)append() ii)add() iii)Sort() iv)rev()
Q20. Komal wants to display the following output identify what will be used to print the
following output with reason :- (2)
Output:
ROLLNO NAME CLASS SECTION
i)print(“ROLLNONAMECLASSSECTION”,end=” “)
ii) print(“ROLLNO”,” NAME”,”CLASS”,” SECTION”,end=” “)
iii) print(“ROLLNO”,” NAME”,”CLASS”,” SECTION”,sep=” “)