import turtle
def draw_square(t, size):
for i in range(4):
t.forward(size)
t.right(90)
def draw_robot():
window = turtle.Screen()
window.bgcolor("white")
window.screensize(800, 800)
rob = turtle.Turtle()
rob.speed(1)
# Draw robot head
rob.penup()
rob.goto(-50, 200) # changed the position
rob.pendown()
draw_square(rob, 100)
# Draw robot body
rob.goto(-75, 100) # changed the position
draw_square(rob, 150)
# Draw robot legs
rob.goto(-75, -50) # changed the position
draw_square(rob, 50)
rob.goto(25, -50) # changed the position
# Draw robot arms
rob.goto(-125, 100) # changed the position
rob.goto(75, 100) # changed the position
window.mainloop()
draw_robot()
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
import turtle
def draw_square(t, size):
for i in range(4):
t.forward(size)
t.right(90)
def draw_robot():
window = turtle.Screen()
window.bgcolor("white")
window.screensize(800, 800)
rob = turtle.Turtle()
rob.speed(1)
# Draw robot head
rob.penup()
rob.goto(-50, 200) # changed the position
rob.pendown()
draw_square(rob, 100)
# Draw robot body
rob.penup()
rob.goto(-75, 100) # changed the position
rob.pendown()
draw_square(rob, 150)
# Draw robot legs
rob.penup()
rob.goto(-75, -50) # changed the position
rob.pendown()
draw_square(rob, 50)
rob.penup()
rob.goto(25, -50) # changed the position
rob.pendown()
draw_square(rob, 50)
# Draw robot arms
rob.penup()
rob.goto(-125, 100) # changed the position
rob.pendown()
draw_square(rob, 50)
rob.penup()
rob.goto(75, 100) # changed the position
rob.pendown()
draw_square(rob, 50)
window.mainloop()
draw_robot()