0% found this document useful (0 votes)
4 views

Python Revision Tour Practice Questions

The document contains a series of sample questions and answers related to Python programming concepts, including code output predictions, dictionary operations, and data types. Each question is followed by multiple-choice options and the correct answer is provided. The questions cover various topics such as string manipulation, list methods, and the behavior of mutable and immutable objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Revision Tour Practice Questions

The document contains a series of sample questions and answers related to Python programming concepts, including code output predictions, dictionary operations, and data types. Each question is followed by multiple-choice options and the correct answer is provided. The questions cover various topics such as string manipulation, list methods, and the behavior of mutable and immutable objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

CODEITUP

codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: Identify the output of the following code snippet:


text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)

1. #THONPROGRAM
2. ##THON#ROGRAM
3. #THON#ROGRAM
4. #YTHON#ROGRAM
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: Identify the output of the following code snippet:


text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)

A. #THONPROGRAM
B. ##THON#ROGRAM
C. #THON#ROGRAM
D. #YTHON#ROGRAM

Answer: (A) #THONPROGRAM


codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Which of the following expressions evaluates to False?
A. not(True) and False
B. True or False
C. not(False and True)
D. True and not(False)
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Which of the following expressions evaluates to False?
A. not(True) and False
B. True or False
C. not(False and True)
D. True and not(False)

Answer: (A) not (True) and False

(A) not (True) and False


codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: What is the output of the expression?
country='International'
print(country.split("n"))
A. ('I', 'ter', 'atio', 'al')
B. ['I', 'ter', 'atio', 'al']
C. ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
D. Error
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: What is the output of the expression?
country='International'
print(country.split("n"))
A. ('I', 'ter', 'atio', 'al')
B. ['I', 'ter', 'atio', 'al']
C. ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
D. Error

Ans: (B) ['I', 'ter', 'atio', 'al']


codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: What will be the output of the following code snippet?

message= "World Peace"


print(message[-2::-2])
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: What will be the output of the following code snippet?

message= "World Peace"


print(message[-2::-2])

Output: ce lo
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: What will be the output of the following code?


tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(A) True
(B) False
(C) tuple1
(D) Error
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: What will be the output of the following code?


tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(A) True
(B) False
(C) tuple1
(D) Error

(B) False
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: If my_dict is a dictionary as defined below, then which of


the following statements will raise an exception?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
(A) my_dict.get('orange')
(B) print(my_dict['apple', 'banana'])
(C) my_dict['apple']=20
(D) print(str(my_dict))
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: If my_dict is a dictionary as defined below, then which of


the following statements will raise an exception?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
(A) my_dict.get('orange')
(B) print(my_dict['apple', 'banana'])
(C) my_dict['apple']=20
(D) print(str(my_dict))

(B) print(my_dict['apple', 'banana'])


codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: What does the list.remove(x) method do in Python?


(A) Removes the element at index x from the list
(B) Removes the first occurrence of value x from the list
(C) Removes all occurrences of value x from the list
(D) Removes the last occurrence of value x from the list
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: What does the list.remove(x) method do in Python?


(A) Removes the element at index x from the list
(B) Removes the first occurrence of value x from the list
(C) Removes all occurrences of value x from the list
(D) Removes the last occurrence of value x from the list

(B) Removes the first occurrence of value x from the list


codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: How is a mutable object different from an immutable object in Python?


Identify one mutable object and one immutable object from the following:
(1,2), [1,2], {1:1,2:2}, ‘123’
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: How is a mutable object different from an immutable object in


Python?
Identify one mutable object and one immutable object from the
following:
(1,2), [1,2], {1:1,2:2}, ‘123’

Answer:
A mutable object can be updated whereas an immutable object
cannot be updated.
Mutable object: [1,2] or {1:1,2:2} (Any one)
Immutable object: (1,2) or ‘123’ (Any one)
(1 mark for correct difference)
(½ x 2 = 1 Mark for selecting correct objects)
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: Give two examples of each of the following:


(I) Arithmetic operators (II) Relational operators
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper

Ques: Give two examples of each of the following:


(I) Arithmetic operators (II) Relational operators

(I) Arithmetic operators: +,-


(II) Relational operators: >, >=
(½ x 4 = 2 Marks for each correct operator)
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
(Answer using builtin functions only)
(I) A) Write a statement to count the occurrences of 4 in L1.
OR
B) Write a statement to sort the elements of list L1 in ascending order.

(II)
A) Write a statement to insert all the elements of L2 at the end of L1.
OR
B) Write a statement to reverse the elements of list L2.
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
(Answer using builtin functions only)
(I) A) Write a statement to count the occurrences of 4 in L1. A) L1.count(4)
OR
B) Write a statement to sort the elements of list L1 in ascending order.
L1.sort()

(II)
A) Write a statement to insert all the elements of L2 at the end of L1.
L1.extend(L2)
OR
B) Write a statement to reverse the elements of list L2.
B) L2.reverse()
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Write a program for the following activity on List.
For example:
If the integers input into the list `VALUES` are:
[10, 5, 8, 3, 12]
Then the stack `EvenNumbers` should store:
[10, 8, 12]
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Predict the output of the following code:
d = {"apple": 15, "banana": 7, "cherry": 9}
str1 = ""
for key in d:
str1 = str1 + str(d[key]) + "@" + “\n”
str2 = str1[:-1]
print(str2)
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Predict the output of the following code:
d = {"apple": 15, "banana": 7, "cherry": 9}
str1 = ""
for key in d:
str1 = str1 + str(d[key]) + "@" + “\n”
str2 = str1[:-1]
print(str2)

Output:
15@
7@
9
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Predict the output of the following code:
line=[4,9,12,6,20]
for I in line:
for j in range(1,I%5):
print(j,’#’,end=””)
print()
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Predict the output of the following code:
line=[4,9,12,6,20]
for I in line:
for j in range(1,I%5):
print(j,’#’,end=””)
print()

Output:
1 #2 #3#
1 #2 #3 #
1#
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: 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.”
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: 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.”

Ans: False
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: 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
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: 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

Answer: Option c [-244.0]


codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Select the correct output of the code:

Options:
a. PYTHON-IS-Fun
b. PYTHON-is-Fun
c. Python-is-fun
d. PYTHON-Is -Fun
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Ques: Select the correct output of the code:

Options:
a. PYTHON-IS-Fun
b. PYTHON-is-Fun
c. Python-is-fun
d. PYTHON-Is –Fun

Output:
b. PYTHON-is-Fun
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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"]
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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"]

Answer: Option b
del D1["Red"]
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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

Answer: Option b
ceieP0
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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
Answer: Option d
Statement 4
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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.
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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.

Answer: Option d
A is false but R is True
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Predict the output of the following code:
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Predict the output of the following code:

4*L
33*4
21*S
10*6
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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.
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


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.

Answer:
(i) L1.insert(2,200)
(ii) message.endswith('.')
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Predict the output of the Python code given below:
codeitup @codeitupyt codeituplearners codeitupyt

Sample Question Paper


Predict the output of the Python code given below:

ND-*34

You might also like