Python MCQ’s on Modules: SET 15

141. The output of the following Python code will result in a shape similar to the alphabet ___________

import turtle

t=turtle.Turtle()

t1=turtle.Turtle()

t.left(45)

t1.left(135)

t.forward(100)

t1.forward(100)

a) V

b) Inverted V

c) X

d) T

Check Answer

Answer: a
In the code shown above, two pens have been used to create a shape similar to the alphabet ‘V’. The angle between the two straight lines is 90 degrees.

142. The output of the following Python code is similar to the alphabet _______________

import turtle

t=turtle.Pen()

t1=turtle.Pen()

t2=turtle.Pen()

t.forward(100)

t1.forward(100)

t2.forward(100)

t1.left(90)

t1.forward(75)

t2.right(90)

t2.forward(75)

a) X

b) N

c) T

d) M

Check Answer

Answer: c
In the above code, three pens have been used to create a shape similar to the letter ‘T’. All the three straight lines are mutually perpendicular.

143. The following Python code will result in an error.

import turtle

t=turtle.Pen()

t.speed(-45)

t.circle(30)

a) True

b) False

Check Answer

Answer: b
Although a negative speed is not possible, the code shown above does not result in an error. Hence, the answer is False.

144. What will be the output of the following Python code?

import turtle()

t=turtle.Pen()

t.goto(50,60)

t1=t.clone()

t1.ycor()

a) 0.0

b) 50.0

c) 60.0

d) Error

Check Answer

Answer: c
The function clone() is used to create a clone of the turtle, having the same properties such as position, coordinates etc. Hence, the properties of the t and t1 are the same in the code shown above. The function ycor() returns the y-coordinate of the turtle. Hence the output of the code is 60.0.

145. What will be the output shape of the following Python code?

import turtle

t=turtle.Pen()

for i in range(0,6):

t.forward(100)

t.left(60)

a) Hexagon

b) Octagon

c) Pentagon

d) Heptagon

Check Answer

Answer: a
The code shown above creates a six-sided polygon. The output shape of the code shown above is will be a hexagon.

146. What will be the output of the following Python code?

import turtle

t=turtle.Pen()

t.resizemode(“sanfoundry”)

t.resizemode()

a) user

b) auto

c) nonresize

d) error

Check Answer

Answer: c
When not explicitly specified as auto or user, no adaption of the turtle’s appearance takes place and the mode is ‘noresize’. Hence the output of the code is: noresize.

147. The process of pickling in Python includes:

a) conversion of a list into a datatable

b) conversion of a byte stream into Python object hierarchy

c) conversion of a Python object hierarchy into byte stream

d) conversion of a datatable into a list

Check Answer

Answer: c
Pickling is the process of sterilizing a Python object, that is, conversion of a byte stream into Python object hierarchy. The reverse of this process is known as unpickling.

148. To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.

a) dumps(), undumps()

b) loads(), unloads()

c) loads(), dumps()

d) dumps(), loads()

Check Answer

Answer: d
To sterilize an object hierarchy, the dumps() function must be called. To desterilize a data stream, the loads function must be called.

149. Pick the correct statement regarding pickle and marshal modules.

a) The pickle module supports primarily .pyc files whereas marshal module is used to sterilize Python objects

b) The pickle module keeps track of the objects that have already been sterilized whereas the marshal module does not do this

c) The pickle module cannot be used to sterilize user defined classes and their instances whereas marshal module can be used to perform this task

d) The format of sterilization of the pickle module is not guaranteed to be supported across all versions of Python. The marshal module sterilization is compatible across all the versions of Python

Check Answer

Answer: b
The correct statement from among the above options is that the python module keeps track of the objects that have already been sterilized whereas the marshal module does not do this. The rest of the statements are incorrect.

150. What will be the output of the following Python code?

pickle.HIGHEST_PROTOCOL

a) 4

b) 5

c) 3

d) 6

Check Answer

Answer: a
There are five protocol versions available of the pickle module, namely, 0, 1, 2, 3 and 4. In the code shown above, the highest protocol version is returned, that is, 4.

Page  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15      16 

Leave a Comment