Introduction
Python Turtle is a helpful tool for learning Python's basic programming syntax. It can be used to teach children programming. It functions similarly to a canvas or easel board, allowing you to draw various figures by sending directions to the Turtle.
The turtle library in Python may be used to create different forms on a canvas. The programmer can direct a pen in a particular direction by specifying its heading and distance. A rectangle or square is not a built-in primitive in Turtle. However, in Turtle, creating a function to draw a rectangle (or square) is simple.
Steps to draw a Square turtle
Approach 1
-
Import a turtle and create an object from it.
-
You may take the length(x) of the square by the user or by yourself.
-
Move the turtle x units forward.
-
Turn the turtle 90 degrees to the left.
-
Iterate it four times so that it makes a closed figure.
Code
# draw a square in Python Turtle
# import turtle library
import turtle
ob = turtle.Turtle()
x = int(input("Enter the length of the Square: "))
# drawing first side
ob.forward(x) # Move the turtle forward by x units
ob.left(90) # Turn turtle by 90 degree
# drawing second side
ob.forward(x) # Move the turtle forward by x units
ob.left(90) # Turn turtle by 90-degree
# drawing third side
ob.forward(x) # Move the turtle forward by x units
ob.left(90) # Turn turtle by 90 degree
# drawing fourth side
ob.forward(x) # Move the turtle by x units
ob.left(90) # Turn the turtle by 90 degree
Input
50
Output

You can compile it with online python compiler.
Approach 2
-
Import a turtle and create an object from it.
-
You may take the length(x) of the square by the user or by yourself.
-
Iterate it four times by loop.
-
Move the turtle x units forward.
-
Turn the turtle 90 degrees to the left.
Code
# draw Square in Python Turtle using loop
# import turtle library
import turtle
ob = turtle.Turtle() # taking input
x = int(input("Enter the length of square: "))
for _ in range(4): # Iterating by loop
ob.forward(x) # Forward turtle by x units
ob.left(90) # Turn turtle by 90 degree
Input
50
Output





