Computer science class 11 CS python topic mcq
1) If you use the following code: user_input = input("Enter your name: "), what will be displayed to
the user?
(A)Enter your name: (B)name (C)user_input (D)None of the above
2) Which of the following is a valid Python keyword?
(A) function (B) def (C) define (D) method
3) Which operator is used to check if two variables refer to the same object?
(A) == (B) is (C) > (D) <
4) What is the output of the following code? print(2**3 // 3 + 2+1*4)
A) 7 (B) 8 (C) 6 (D)10
5) Which of the following is the correct syntax to declare a variable in Python?
(A) var x = 10 (B) x := 10 (C) x = 10 (D) int x = 10
6) Which of the following is true about tuples?
(A) Tuples are mutable (B) Tuples are immutable
(C) Tuples can grow in size (D) None of the above
7) Given my_dict = {'ball': 2, 'bat': 5}, what does my_dict['ball'] = 4 do?
(A) Raises an error (B) Changes the value of 'ball' to 4
(C) Deletes 'ball' from the dictionary (D) Creates a new key-value pair
8) What is the correct syntax to access the second element of a list my_list?
(A) my_list(1) (B) my_list[1] (C) my_list{1} (D) my_list.1
9) What is the default return value of a function that doesn't have a return statement?
(A) None (B) 0 (C) Empty string "" (D) Error
10) What is the output of the following code?
x=5
y = 10
print(x < y and y > 5)
(A) True (B) False (C) Error (D) None
11) What is the output of the following code?
for i in range(1, 6):
if i == 3:
break
print(i)
(A) 1 (B) 2 (C) 2 (D) 0
2 1 3 1
0 1
12) What will be the output of the following code?
print("Hello"[0])
(A) H (B) e (C) o (D)l
13) What is the output of the following code?
text = "banana"
text = text.replace('a', 'o')
print(text)
(A) bonono (B) banana (C) bonana (D) banono
14) What is the output of print("Machine Learning"[5:1:-1])?
(A) enih (B) eniM (C) ih (D) nihc
15) What is the output of this code?
text = "Welcome to Python"
text = text.split()
print(text)
(A) ['Welcome', 'to', 'Python'] (B) ['Welcome', 'toPython']
(C) ['Welcome to Python'] (D) ['Welcome', 'to', '', 'Python']
16) What is the output of the following code?
a = [1, 2, 3]
b=a
a.append([4,5])
print(b)
(A) [1, 2, 3] (B) [1, 2, 3, [4, 5]] (C) [4, 3, 2, 1] (D) Error
17) What will be the output of the following code?
x=5
def test():
x=3
print(x, end=' ')
test()
print(x)
(A) 3 5 (B) 5 3 (C) 3 3 (D) 5 5
18) What is the output of the following code?
def func(y, x=[]):
x.append(y)
return x
print(func(10))
print(func(20))
(A) [10] (B) [10] (C) [10]
[20] [10, 20] [20] (D) Error
19) What will be the output of the following Python code?
values = [1, 2, 3, 4, 5]
squared = []
for value in values:
squared.append(value ** 2)
print(squared)
(A)[1, 4, 9, 16, 25] (B)[1, 2, 3, 4, 5]
(C)[1, 8, 27, 64, 125] (D)[1, 2, 3, 4, 5, 6]
Q20 and Q21 are Assertion(A) and Reason(R) 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
20) Assertion (A): A Python dictionary is a mutable data type.
Reason (R): Dictionary keys in Python can be changed after creation.
21) Assertion (A): The break statement in Python is used to exit a loop.
Reason (R): The break statement in Python is only applicable in for loops.