You are on page 1of 14

Python Revision Tour

MCQ
Q1 Which of the following is valid arithmetic operator in Python:
(i) // (ii) ? (iii) < (iv) and (1)
A1 (i) //
Q2 Write the type of tokens from the following:
(i) if (ii) roll_no (1)
A2 (i) Key word (ii) Identifier
Q3 Name the Python Library modules which need to be imported to invoke the
following functions:
(i) sin() (ii) randint () (1)
A3 (i) math (ii) random (1)
Q4 What do you understand by the term Iteration? (1)
A4 Repetition of statement/s finite number of times is known as Iteration. (1)
Q5 Which is the correct form of declaration of dictionary?
(i) Day={1:’monday’,2:’tuesday’,3:’wednesday’}
(ii) Day=(1;’monday’,2;’tuesday’,3;’wednesday’)
(iii) Day=[1:’monday’,2:’tuesday’,3:’wednesday’]
(iv) Day={1’monday’,2’tuesday’,3’wednesday’] (1)
A5 (i) Day={1:’monday’,2:’tuesday’,3:’wednesday’} (1)
Q6 Identify the valid declaration of L:
L = [1, 23, ‘hi’, 6].
(i) list (ii) dictionary (iii) array (iv) tuple (1)
A6 (i) list (1)
SP20
Q7 Find the invalid identifier from the following
a) MyName b) True c) 2ndName d) My_Name (1)
A7b) True (1)
Q8 Identify the valid arithmetic operator in Python from the following.
a) ? b) < c) ** d) and (1)

1
A8 c) ** (1)
Q9 Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is
incorrect?
a) print(T[1]) b) T[2] = -29 c) print(max(T)) d) print(len(T)) (1)
A9 b) T[2]= -29 (as tuple is immutable) (1)
Q10 Identify the valid declaration of L:
L = [‘Mon’, ‘23’, ‘hello’, ’60.5’]
a. dictionary b. string c.tuple d. list (1)
A10 d. List (1)
Q11 Rearrange the following terms in increasing order of data transfer rates.
Gbps, Mbps, Tbps, Kbps, bps (1)
A11 Bps, Kbps, Mbps, Gbps, Tbps (1)
Q12 Find the invalid identifier from the following
a. none b. address c. Name d. pass (1)
A12 d. pass (1)
Q13 Consider a declaration L = (1, 'Python', '3.14').
Which of the following represents the data type of L?
a. list b. tuple c. dictionary d. string (1)
A13 b. tuple (1)
Q14 Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80) b. (40,50,60,70) c. [40,60] d. (40,60) (1)
A14 d. (40,60) (1)
Q15 The return type of the input() function is
a. string b. integer c. list d. tuple (1)
A15 a. string (1)
Q16 Which of the following operator cannot be used with string data type?
a. + b. in c. * d. / (1)
A16 d. / (1)
Q17 Consider a tuple tup1 = (10, 15, 25, and 30). Identify the statement that will
result in an error.

2
a. print(tup1[2]) b. tup1[2] = 20 c. print(min(tup1)) d. print(len(tup1)) (1)
A17 b. tup1[2] = 20 (1)
Q18 Which one of the following is the default extension of a Python file?
a. .exe b. .p++ c. .py d. .p (1)
A18 c. .py (1)
Q19 Which of the following symbol is used in Python for single line comment?
a. / b. /* c. // d. # (1)
A19 d. # (1)
Q20 Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable (1)
A20 b) The keys of a dictionary can be accessed using values (1)
Q21 What is the output of following code:
T=(100)
print(T*2)
a. Syntax error b. (200,) c. 200 d. (100,100) (1)
A21 c. 200 (1)
Q22 Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a. 12.0 b. 13.0 c. 14.0 d. 15.0
A22 d. 15.0 (1)
Q23 Identify the output of the following Python statements.
x=2
while x < 9:
print(x, end='')
x=x+1

3
a. 12345678 b. 123456789 d. 23456789
A23 c. 2345678 (1)
Q24 Identify the output of the following Python statements.
b=1
for a in range(1, 10, 2):
b += a + 2
print(b)
a. 31 b. 33 c. 36 d. 39
A24 c. 36 (1)
Q25 Identify the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
a. 2 b. 3 c. 4 d. 20
A25 b. 3 (1)
Q26 Find the output of the following code:
Name="PythoN3.1"
R=""
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)
a. pYTHOn##@ b. pYTHOnN#@ c. pYTHOn#@ d. pYTHOnN@#

4
A26 b. pYTHOnN#@
Q27 What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
a. (1,2,[3.14,2],3) b. (1,2,[1,3.14],3)
c. (1,2,[1,2],3.14) d. Error Message
A27 d. Error Message
Q28 Which of the following is an invalid datatype in Python?
(a) Set (b) None (c)Integer (d)Real (1)
A28 (d)Real (1)
Q29 Given the following dictionaries
dict_exam={"Exam":"AISSCE", "Year":2023}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?
a. dict_exam.update(dict_result)
b. dict_exam + dict_result
c. dict_exam.add(dict_result)
d. dict_exam.merge(dict_result) (1)
A29 a. dict_exam.update(dict_result) (1)
Q30 Consider the given expression:
not True and False or True
Which of the following will be correct output if the given expression is evaluated?
(a) True (b) False (c) NONE (d) NULL (1)
A30(a) True (1)
Q31 Select the correct output of the code:
a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)

5
(a) Year . 0. at All the best (b) Year 0. at All the best
(c) Year . 022. at All the best (d) Year . 0. at all the best (1)
A31 (a) Year . 0. at All the best (1)
Q32 Which of the following statement(s) would give an error after executing the
following code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3 (b) Statement 4 (c) Statement 5 (d) Statement 4 and 5 (1)
A32 (b) Statement 4 (1)
Q33 What will the following expression be evaluated to in Python?
print(15.0 / 4 + (8 + 3.0))
(a) 14.75 (b)14.0 (c) 15 (d) 15.5 (1)
A33 (a) 14.75 (1)

Q34 What will be the output of the following statement:


print(3-2**2**3+99/11)
a. 244 b. 244.0 c. -244.0 d. Error (1)
A34 Option c
-244.0 (1)
Q35 Select the correct output of the code:
S= “Python is fun”
l=s.split( )
s_new=”-“.join( [1 [0] .upper( ) , 1 [1] ,1 [2] .capitalize( ) ])
print(s_new)

Options:
a. PYTHON-IS-Fun b. PYTHON-is-Fun c. Python-is-fun d. PYTHON-Is -Fun (1)

A35 b. PYTHON-is-Fun (1)


Q36 Which of the following will delete key-value pair for key = “Red” from a
dictionary D1?
a. delete D1("Red") b. del D1["Red"] c. del.D1["Red"] d. D1.del["Red"] (1)

6
A36 Option b
del D1["Red"] (1)
Q37 Consider the statements given below and then choose the correct output from
the given options:
pride="#G20 Presidency"
print(pride[-2:2:-2])
Options
a. ndsr b. ceieP0 c. ceieP d. yndsr (1)
A37 Option b
ceieP0 (1)

Q38 Which of the following statement(s) would give an error during execution of the
following code?
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4
Options:
a. Statement 1 b. Statement 2 c. Statement 3 d. Statement 4 (1)
A38 Option d
Statement 4 (1)

ASSERTION AND REASONING


Q1 is 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): List is an immutable data type


Reasoning(R): When an attempt is made to update the value of an immutable
variable, the old variable is destroyed and a new variable is created by the same
name in memory. (1)

A1 Option d
A is false but R is True (1)

7
Find the output
Q1 What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the maximum
values that can be assigned to each of the variables FROM and TO.
import random
AR=[20,30,40,50,60,70];
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1):
print (AR[K],end=”#“)
(i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70# (2)
A1 OUTPUT: (ii) 30#40#50#
Maximum value of Lower: 3
Maximum value of Upper: 4 (2)
Q2 Find and write the output of the following python code:
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ") (2)
A2 aaaaaa----- OR infinite loop (2)
Q3 A tuple is declared as
T = (2,5,6,9,8)
What will be the value of sum(T)? (1)
A3 30 (1)
Q4 If the following code is executed, what will be the output of the following code?
name="ComputerSciencewithPython"
print(name[3:10]) (1)
A4 puterSc

8
Q5 What will be the output of the following code?
import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = random.randint(1,3)
print(List[x],end="#")
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
A5 b. Mumbai#Chennai#Kolkata#Mumbai#
Q6 Predict the output of the Python code given below:
tuple1 = (11, 22, 33, 44, 55 ,66)
list1 =list(tuple1)
new_list = [ ]
for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)

A6 (22,44,66)

Q7 Predict the output of the code given below:


s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()

9
else:
m = m +'&'
print(m)
A7 Output:
105#6#
Q8 What possible outputs(s) will be obtained when the following code is
executed?
import random
myNumber = random.randit (0,3)
COLOR = [“YELLOW”, ”WHITE”, “BLACK”, ”RED”]
for I in COLOR:
for J in range (1, myNUmber):
print(I, end= “*”)
print( )
Options:
a.
RED*
WHITE*
BLACK*
RED*

b.
YELLOW*
WHITE*
BLACK*
RED*

c.
WHITE* WHITE*
YELLOW* YELLOW*
BLACK* BLACK*
RED* RED*

d.
YELLOW*
WHITE*WHITE*
BLACK* BLACK* BLACK*
RED* RED* RED* RED* RED*

10
A8
Option b
YELLOW*
WHITE*
BLACK*
RED*

Q9 Given is a Python string declaration:


myexam="@@CBSE Examination 2022@@"
Write the output of: print(myexam[::-2])
A9 @20 otnmx SC@

Q10 Write the output of the code given below:


my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())

A10 dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])

Q11 Predict the output of the Python code given below:

Text1=”IND-23”
Text2=” “
I=0
while I<len(Text1):
if Text1[I] >= “0” and Text1[I] <= “9”:
Val = int (Text1 [1])
Val = Val +1
Text2 = Text2 +str (Val)
elif Text1 [I] >=”A” and Text1 [i]<= “Z”:
Text2 = Text2 + (Text1 [ I +1] )
else :
Text2 = Text2 + “*”

11
I+=1
print (Text2) (3)
A11 ND-*34 (3)

Evaluate the expressions

Q1 Evaluate the following expressions:


a) 6 * 3 + 4**2 // 5 – 8
b) 10 > 5 and 7 > 12 or not 18 > 3 (2)
A1 a) 13 b) False (2)

Q2 Evaluate the following expression and identify the correct answer.


16 - (4 + 2) * 5 + 2**3 * 4
a. 54 b. 46 c. 18 d. 32
A2 c. 18

Rewrite the code after removing all syntax error(s).

Q1 Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
30=To
for K in range(0,To)
IF k%4==0:
print (K*4)
Else:
print (K+3) (2)
A1
To=30 #1Error
for K in range(0,To) : #2Error
if k%4==0: #3Error
print (K*4)
else: #4Error
print (K+3)

12
Q2 Rewrite the following code in Python after removing all syntax error(s).
Underline each correction done in the code.
Value=30
for VAL in range(0,Value)
If val%4==0:
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10) (2)
A2 CORRECTED CODE:
Value=30
for VAL in range(0,Value) : # Error 1
if val%4==0: # Error 2
print (VAL*4)
elif val%5==0: # Error 3
print (VAL+3)
else: # Error 4
print(VAL+10) (2)

Write statement

Q1 Write a statement in Python to declare a dictionary whose keys are 1, 2, 3


and values are Monday, Tuesday and Wednesday respectively. (1)
A1 Day={1:'monday',2:'tuesday',3:'wednesday'} (1)
Q2 Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
(i) To insert an element 200 at the third position, in the list L1.
(ii) To check whether a string named, message ends with a full stop / period or
not. (2)

A2
(i) L1.insert(2,200)
(ii) message.endswith('.') (2)

13
State True or False
Q1 State True or False
“Variable declaration is implicit in Python.” (1)
A1 True (1)
Q2 State True or False:
“In a Python program, if a break statement is given in a nested loop, it terminates the
execution of all loops in one go.” (1)
A2 False (1)
Q3 State whether the following statement is True or False:
An exception may be raised even if the program is syntactically correct. (1)
A3True (1)

14

You might also like