Test Series - python

Test Number 88/108

Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.color(0,0,1)
t.begin_fill()
t.circle(15)
t.end_fill()
A. Error
B. A circle filled in with the colour red
C. A circle filled in with the colour blue
D. A circle filled in with the colour green
Solution: The function t.colour(0, 0, 1) is used to fill in the colour blue into any given shape. Hence the output of the code shown above will be a circle filled in with the colour blue.
Q: Which of the following functions can be used to make the arrow black?
A. turtle.color(0,1,0)
B. turtle.color(1,0,0)
C. turtle.color(0,0,1)
D. turtle.color(0,0,0)
Solution: The function turtle.color(0,0,0) can change the colour of the arrow. The function turtle.color(0,1,0) will make the arrow green. The function turtle.color(1,0,0) will make the arrow red. The function turtle.color(0,0,1) will make the arrow blue. The function turtle.color(0,0,0) will make the arrow black.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.color(1,1,1)
t.begin_fill()
for i in range(0,3):
	t.forward(100)
	t.right(120)
              t.end_fill()
A. Blank page
B. A triangle filled in with the colour yellow
C. A triangle which is not filled in with any colour
D. Error
Solution: The code shown above will result in a blank page. This is because the command turtle.color(1,1,1) eliminates the arrow from the page. Hence all the commands after this command are ineffective.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.color(0,1,0)
t.begin_fill()
for i in range(0,4):
	t.forward(100)
	t.right(90)
A. A square filled in with the colour green
B. A square outlined with the colour green
C. Blank canvas
D. Error
Solution: The output shape of the code shown above is a square, outlined with the colour green, but not filled in with any colour. This is because we have not used the command t.end_fill() at the end.
Q: In which direction is the turtle pointed by default?
A. North
B. South
C. East
D. West
Solution: By default, the turtle is pointed towards the east direction. We can change the direction of the turtle by using certain commands. However, whenever the turtle is reset, it points towards east.
Q: The command used to set only the x coordinate of the turtle at 45 units is:
A. reset(45)
B. setx(45)
C. xset(45)
D. xreset(45)
Solution: The command setx(45) is used to set the x coordinate of the turtle. Similarly, the command sety() is used to set the y coordinate of the turtle. The function reset() takes two values as arguments, one for the x-coordinate and the other for the y-coordinate.
Q: Which of the following functions returns a value in degrees, counterclockwise from the horizontal right?
A. heading()
B. degrees()
C. position()
D. window_height()
Solution: The function heading() returns the heading of the turtle, which is a value in degrees counterclockwise from the horizontal right. This measure will be in radians if radians() has been called.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.right(90)
t.forward(100)
t.heading()
A. 0.0
B. 90.0
C. 270.0
D. 360.0
Solution: The output of the code shown above will be 270.0. The function heading() returns the heading of the turtle, a value in degrees, counterclockwise from the horizontal right. The output shape of this code is a straight line pointing downwards.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.clear()
t.isvisible()
A. Yes
B. True
C. No
D. False
Solution: The function t.clear() returns a blank canvas, without changing the position of the turtle. Since the turtle is visible on the blank canvas, the output of this code is: Yes.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.forward(100)
t.left(90)
t.clear()
t.position()
A. 0.00, 90.00
B. 0.00, 0.00
C. 100.00, 90.00
D. 100.00, 100.00
Solution: The output of the code shown above is 100.00, 100.00. The function clear() is used to erase the entire canvas and redraw the turtle. However, the position of the turtle is not changed.

You Have Score    /10