Test Series - python

Test Number 87/108

Q: 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
Solution: 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.
Q: 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
Solution: The number of lines drawn in the first case is 10, while that in the second case is 9.
Q: The command which helps us to reset the pen (turtle):
A. turtle.reset
B. turtle.penreset
C. turtle.penreset()
D. turtle.reset()
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: The code shown above will result in the formation of a square, with each of side 60.
Q: 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
Solution: 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.
Q: Which of the following functions does not accept any arguments?
A. position
B. fillcolor
C. goto
D. setheading()
Solution: The functions fillcolor(), goto() and setheading() accept arguments, whereas the function position() does not accept any arguments. The function position() returns the current position of the turtle.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.goto(300,9)
t.position()
A. 300.00, 9.00
B. 9, 300
C. 300, 9
D. 9.00, 300.00
Solution: The goto functions takes the arrow to the position specified by the user as arguments. The position function returns the current position of the arrow. Hence the output of the code shown above will be: 300.00, 9.00.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
for i in range(0,5):
        t.left(144)
        t.forward(100)
A. Trapezium
B. Parallelepiped
C. Tetrahedron
D. Star
Solution: It is clear from the above code that 5 lines will be drawn on the canvas, at an angle of 144 degrees. The only shape which fits this description is star. Hence the output of the code shown above is star.
Q: What will be the output of the following Python functions?

import turtle
t=turtle.Pen()
for i in range(0,3):
	t.forward(100)
	t.left(120)
 
t.back(100)
for i in range(0,3):
	t.forward(100)
	t.left(120)
A. Error
B. Two triangles, joined by a straight line
C. Two triangles, joined at one vertex
D. Two separate triangles, not connected by a line
Solution: The output of the code shown above is two equilateral triangles (of side 100 units), joined at the vertex.

You Have Score    /10