What will be the output of the following Python code? [code]import turtle t=turtle.Pen() for i in range(0,4): t.forward(100) t.left(90) t.penu

What will be the output of the following Python code?
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
 
Answer: b
Explanation: 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.
 

Tìm kiếm

Back
Top