Python MCQ’s on Modules: SET 12

111. Which of the following returns a string that represents the present working directory?

a) os.getcwd()

b) os.cwd()

c) os.getpwd()

d) os.pwd()

Check Answer

Answer: a
The function getcwd() (get current working directory) returns a string that represents the present working directory.

112. What does os.link() do?

a) create a symbolic link

b) create a hard link

c) create a soft link

d) none of the mentioned

Check Answer

Answer: b
os.link(source, destination) will create a hard link from source to destination.

113. Which of the following can be used to create a directory?

a) os.mkdir()

b) os.creat_dir()

c) os.create_dir()

d) os.make_dir()

Check Answer

Answer: a
The function mkdir() creates a directory in the path specified.

114. Which of the following can be used to create a symbolic link?

a) os.symlink()

b) os.symb_link()

c) os.symblin()

d) os.ln()

Check Answer

Answer: a
It is the function that allows you to create a symbolic link.

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

import turtle

t=turtle.Pen()

for i in range(0,4):

t.forward(100)

t.left(120)

a) square

b) rectangle

c) triangle

d) kite

Check Answer

Answer: c
According to the code shown above, 4 lines will be drawn. Three lines will be in the shape of a triangle. The fourth line will trace the base, which is already drawn. Hence the base will be slightly thicker than the rest of the lines. However there will be no change in the shape due to this extra line. Hence the output shape will be a triangle.

116. The number of lines drawn in each case, assuming that the turtle module has been imported:

Case 1:

for i in range(0,10):

turtle.forward(100)

turtle.left(90)

Case 2:

for i in range(1,10):

turtle.forward(100)

turtle.left(90)

a) 10, 9

b) 9, 10

c) 9, 9

d) 10, 10

Check Answer

Answer: a
The number of lines drawn in the first case is 10, while that in the second case is 9.

117. The command which helps us to reset the pen (turtle):

a) turtle.reset

b) turtle.penreset

c) turtle.penreset()

d) turtle.reset()

Check Answer

Answer: d
The command turtle.reset() helps us to reset the pen. After the execution of this command, we get a blank page with an arrow on it. We can then perform any desired operation on this page.

118. Fill in the blank such that the following Python code results in the formation of an inverted, equilateral triangle.

import turtle

t=turtle.Pen()

for i in range(0,3):

t.forward(150)

t.right(_____)

a) -60

b) 120

c) -120

d) 60

Check Answer

Answer: b
An angle of -120 will result in the formation of an upright, equilateral triangle. An angle of 120 will result in the formation of an inverted triangle. The angles of 60 and -60 do not result in the formation of a triangle.

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

import turtle

t=turtle.Pen()

for i in range(1,4):

t.forward(60)

t.left(90)

a) Rectangle

b) Trapezium

c) Triangle

d) Square

Check Answer

Answer: d
The code shown above will result in the formation of a square, with each of side 60.

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

import turtle

t=turtle.Pen()

for i in range(0,4):

t.forward(100)

t.left(90)

t.penup()

t.left(90)

t.forward(200)

for i in range(0,4):

t.forward(100)

t.left(90)

a) Error

b) 1 square

c) 2 squares, at a separation of100 units, joined by a straight line

d) 2 squares, at a separation of 100 units, without a line joining them

Check Answer

Answer: b
The output of the code shown above will be a single square. This is because the function t.penup() is used to lift the pen after the construction of the first square. However, the function t.pendown() has not been used to put the pen back down. Hence, the output shape of this code is one square, of side 100 units.

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

Leave a Comment