Test Series - python

Test Number 89/108

Q: Which of the following functions results in an error?
A. turtle.shape(“turtle”)
B. turtle.shape(“square”)
C. turtle.shape(“triangle”)
D. turtle.shape(“rectangle”)
Solution: The functions shown above will change the arrow to the shape mentioned. The functions turtle.shape(“turtle”), turtle.shape(“square”) and turtle.shape(“triangle”) are valid whereas the function turtle.shape(“rectangle”) is invalid.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen
t.tilt(75)
t.forward(100)
A. A straight line of 100 units tiled at 75 degrees from the horizontal
B. A straight line of 100 units tilted at 15 degrees from the horizontal
C. A straight line of 100 units lying along the horizontal
D. Error
Solution: The function turtle.tilt(75) will tilt the turtle. But the straight line (of 100 units) is drawn along the horizontal. Hence the output of the code shown above is a straight line of 100 units lying along the horizontal.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.backward(100)
t.penup()
t.right(45)
t.isdown()
A. True
B. False
C. Yes
D. No
Solution: In the code shown above, we have used the function t.penup() to life the pen from the canvas. However, we have not used the function t.pendown() to keep the pen back down. The function turtle.isdown() returns True if the pen is down and False if the pen is not down. Hence the output is False.
Q: The function used to alter the thickness of the pen to ‘x’ units:
A. turtle.width(x)
B. turtle.span(x)
C. turtle.girth(x)
D. turtle.thickness(x)
Solution: The function turtle.width(x) is used to alter the thickness of the pen to ‘x’ units. The function turtle.span(x), turtle.girth(x) and turtle.thickness(x) are invalid.
Q: What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?

import turtle
t=turtle.Pen()
t.goto(100,0)
t.towards(0,0)
A. 0.0
B. 180.0
C. 270.0
D. 360.0
Solution: The function t.towards(x,y) returns the angle between the line to the line specified by (x,y). Hence the output will be 180.0.
Q: What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.position()
(100.00,0.00)
t.goto(100,100)
t.distance(100,0)
A. 0.0
B. Error
C. 100.0, 100.0
D. 100.0
Solution: The distance() function returns the distance between the turtle to the given vector. Hence the output of the code shown above is 100.0.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: The following Python code will result in an error.

import turtle
t=turtle.Pen()
t.speed(-45)
t.circle(30)
A. True
B. False
C. none
D. yes
Solution: Although a negative speed is not possible, the code shown above does not result in an error. Hence, the answer is False.
Q: 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
Solution: 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.

You Have Score    /10