an HCL GUVI product

python banner

Python Multiple Choice Questions (MCQs) and Answers

Master Python Programming with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Python Programming. Begin your placement preparation journey now!

Q91

Q91 Pseudocode:

Initialize a variable with "Python", print first and last character

A

Prints "Pn"

B

Prints "Py"

C

Prints "Python"

D

Error

Q92

Q92 Find the mistake:

user_input = input("Enter a number: ");
print("You entered: ", int(user_input))

A

Syntax error

B

No error

C

int() should be str()

D

input() function used incorrectly

Q93

Q93 What is the purpose of an if statement in Python?

A

To loop through a sequence

B

To execute a block conditionally

C

To define a function

D

To handle exceptions

Q94

Q94 In Python, which keyword is used to check additional conditions if the previous conditions fail?

A

elif

B

else if

C

then

D

switch

Q95

Q95 Which of the following is a valid conditional statement in Python?

A

if a = 5:

B

if a == 5:

C

if a <> 5:

D

if (a = 5):

Q96

Q96 Pseudocode:

If age > 18,
print "Adult",
else
print "Minor"

A

Prints "Adult"

B

Prints "Minor"

C

Prints "Age"

D

No output

Q97

Q97 Pseudocode: What is printed when the temperature is 25 degrees?

If temperature > 30,
print "Hot",
elif temperature > 20,
print "Warm",
else
"Cold"

A

Prints "Hot"

B

Prints "Warm"

C

Prints "Cold"

D

No output

Q98

Q98 Find the mistake:

if x > 5:
print("Yes")
elif x < 10:
print("No")

A

Syntax error in the if block

B

Missing colon after elif

C

Missing else between blocks

D

No error

Q99

Q99 Which statement immediately terminates a loop in Python?

A

break

B

continue

C

exit

D

stop

Q100

Q100 In a while loop, what happens if the condition never becomes False?

A

The loop runs forever

B

The loop stops after 10 iterations

C

Syntax error

D

The loop doesn't start

Q101

Q101 What will the following code print?

i = 5;
while i > 0:
print(i);
i -= 1

A

5 4 3 2 1

B

5 4 3 2

C

1 2 3 4 5

D

Infinite loop

Q102

Q102 Pseudocode:

For each element in list [1, 2, 3],
print element

A

Prints 1 2 3

B

Prints 3 2 1

C

Prints [1, 2, 3]

D

No output

Q103

Q103 Pseudocode:

For i = 0 to 4,
print "Python"
if i is even

A

Prints "Python" twice

B

Prints "Python" three times

C

Prints "Python" four times

D

No output

Q104

Q104 How is memory allocation for lists and tuples different in Python?

A

Lists use more memory than tuples

B

Tuples use more memory than lists

C

Both use the same amount of memory

D

Memory usage is random and unpredictable

Q105

Q105 What will be the output of the following code?

myTuple = (1, 2, 3);
print(myTuple[1])

A

1

B

2

C

3

D

Error

Q106

Q106 What is the result of the following code?

myList = [1, 2, 3];
myList[1] = 4;
print(myList)

A

[1, 2, 3]

B

[1, 4, 3]

C

Error

D

[4, 2, 3]

Q107

Q107 Pseudocode:

Initialize list with values [1,2,3];
Add 4 to the end;
Print list

A

Prints [1, 2, 3]

B

Prints [1, 2, 3, 4]

C

Error

D

Prints [4, 1, 2, 3]

Q108

Q108 Pseudocode:

Given a tuple (1,2,3),
print each element multiplied by 2

A

Prints 2, 4, 6

B

Prints 1, 2, 3

C

Error

D

No output

Q109

Q109 Find the mistake:

myTuple = (1, 2, 3);
myTuple[1] = 4

A

Tuples are immutable

B

Wrong index used

C

Syntax error in tuple declaration

D

myTuple should be a list

Q110

Q110 What is a dictionary in Python?

A

An ordered collection of elements

B

A mutable collection of key-value pairs

C

An immutable collection of items

D

A collection of unique elements

Q111

Q111 What happens if you try to access a non-existent key 'k' in a dictionary 'd' using d[k]?

A

Returns None

B

Returns an empty string

C

Raises a KeyError

D

Creates a new key 'k' with value None

Q112

Q112 How can you remove a key-value pair from a dictionary?

A

Using the del statement

B

Using the remove() method

C

Using the pop() method

D

Both A and C

Q113

Q113 In Python 3.7 and later, how are elements in a dictionary ordered?

A

By the order they were added

B

In ascending order of keys

C

In descending order of keys

D

Randomly

Q114

Q114 What is the output of the following code?

d = {'a': 1, 'b': 2};
print(d['b'])

A

1

B

2

C

b

D

KeyError

Q115

Q115 What will be the result of the following code?

d = {'a': 1, 'b': 2};
d['c'] = 3;
print(len(d))

A

2

B

3

C

Error

D

1

Q116

Q116 Pseudocode:

Initialize dictionary with {'a': 1, 'b': 2};
Update 'b' value to 3;
Print dictionary

A

Prints {'a': 1, 'b': 2}

B

Prints {'a': 1, 'b': 3}

C

Error

D

No output

Q117

Q117 Pseudocode:

Given a dictionary,
print each key-value pair

A

Prints keys only

B

Prints values only

C

Prints key-value pairs

D

Error

Q118

Q118 Identify the error:
d = {['first']: 1, ['second']: 2}

A

Syntax error with the dictionary

B

Lists can't be dictionary keys

C

No error

D

Dictionary keys must be strings

Q119

Q119 What is a function in Python?

A

A variable

B

A module

C

A block of code

D

An operator

Q120

Q120 What will the following function return:

def example():
return 5+5

A

5+5

B

10

C

0

D

None