Turtle


import turtle

Screen setup

screen = turtle.Screen()
screen.bgcolor("lightblue") # Set background color

Create a turtle object

t = turtle.Turtle()
t.shape("turtle")
t.speed(2)

Function to draw a square

def draw_square():
t.color("black") # Border color
t.fillcolor("yellow") # Fill color
t.begin_fill()
for _ in range(4):
t.forward(100)
t.right(90)
t.end_fill()
t.penup()
t.goto(-150, 0) # Move to a new position for the next shape
t.pendown()

Function to draw a rectangle

def draw_rectangle():
t.color("purple")
t.fillcolor("orange")
t.begin_fill()
for _ in range(2):
t.forward(150) # Longer side
t.right(90)
t.forward(80) # Shorter side
t.right(90)
t.end_fill()
t.penup()
t.goto(150, 0) # Move to a new position for the next shape
t.pendown()

Function to draw a star

def draw_star():
t.color("blue")
t.fillcolor("pink")
t.begin_fill()
for _ in range(5):
t.forward(100)
t.right(144)
t.end_fill()

Draw shapes

draw_square()
draw_rectangle()
draw_star()

Hide the turtle and display the window

t.hideturtle()
turtle.done()