Draw Square and Rectangle in Turtle - Python
Last Updated :
11 Apr, 2025
The task of drawing basic geometric shapes, such as squares and rectangles, can be accomplished using Python's Turtle graphics library. Turtle graphics enables us to create shapes and patterns by controlling a "turtle" on the screen. Using simple commands like forward(), backward(), and others, we can easily draw squares and rectangles.
To get started with the Turtle module, you need to import it into your Python script:
import turtle
Drawing Square
Using Manual Turning (Non-loop Method)
In this approach, we will manually draw each side of the square and turn the turtle 90 degrees after each side. The process is repeated four times to complete the square.
Python
import turtle
t = turtle.Turtle()
s = int(input("Enter the length of the side of the Square:"))
# drawing first side
t.forward(s)
t.left(90)
# drawing second side
t.forward(s)
t.left(90)
# drawing third side
t.forward(s)
t.left(90)
# drawing fourth side
t.forward(s)
t.left(90)
Input
100
Output

Explanation: In this code, we start by asking the user for the length of the side of the square. Then, we manually draw each side of the square by using t.forward(s) to move the turtle forward by s units and t.left(90) to turn the turtle by 90 degrees after each side. This process is repeated four times, each time drawing one side of the square. The left(90) ensures the turtle turns by 90 degrees to form right angles.
Using Loop
This method uses a loop to repeat the process of drawing each side of the square, reducing redundancy and making the code more efficient.
Python
import turtle
t = turtle.Turtle()
s = int(input("Enter the length of the side of square:"))
for _ in range(4):
t.forward(s)
t.left(90)
Input
100
Output

Explanation: In this approach, the user is again prompted to enter the side length of the square. A loop runs four times (for _ in range(4)), and during each iteration, the turtle moves forward by the specified side length (t.forward(s)) and turns 90 degrees (t.left(90)). This method achieves the same result as the first, but in a more concise and reusable manner by utilizing a loop instead of manually repeating the commands.
Drawing Rectangle
Using Manual Turning (Non-loop Method)
In this approach, we will manually draw each side of a rectangle and turn the turtle by 90 degrees after each side. The process is repeated for all four sides of the rectangle.
Python
import turtle
t = turtle.Turtle()
l = int(input("Enter the length:"))
w = int(input("Enter the width:"))
# drawing first side
t.forward(l)
t.left(90)
# drawing second side
t.forward(w)
t.left(90)
# drawing third side
t.forward(l)
t.left(90)
# drawing fourth side
t.forward(w)
t.left(90)
Input
100
120
Output

Explanation: In this code, the user is asked to input the length (l) and width (w) of the rectangle. The turtle then begins drawing by moving forward by the length of the rectangle (t.forward(l)) and turns 90 degrees using t.left(90). The process is repeated for the second side (width), and this continues for the remaining two sides of the rectangle.
Using Loop
This method uses a loop to draw the rectangle, making the code more compact and reusable while alternating between length and width.
Python
import turtle
t = turtle.Turtle()
l = int(input("Enter the length:"))
w = int(input("Enter the width:"))
for _ in range(4):
# drawing length
if _% 2 == 0:
t.forward(l)
t.left(90)
# drawing width
else:
t.forward(w)
t.left(90)
Input
100
120
Output

Explanation: This approach uses a loop (for _ in range(4)) to repeat the drawing steps. The loop alternates between drawing the length and the width of the rectangle using an if condition (if _% 2 == 0). For even iterations (_ % 2 == 0), the turtle moves forward by the length of the rectangle, and for odd iterations, it moves forward by the width. After each side, the turtle turns by 90 degrees (t.left(90)).
Drawing a Character Using Turtle Graphics
Since as of now, you must have learned how to draw various basic geometrical illustrations like circle, square, rectangle. So, let's implement this knowledge to build something which you can really use in building games like let's draw a human being using the basic knowledge of geometrical knowledge.
Python
import turtle
def draw_dream():
window = turtle.Screen()
window.bgcolor("white")
draw_Scarlett()
window.exitonclick()
def draw_Scarlett():
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("red")
draw_head(brad)
draw_body(brad)
draw_arm(brad)
draw_leg1(brad)
draw_leg2(brad)
def draw_head(brad):
brad.circle(60)
brad.speed(3)
brad.right(60)
def draw_body(brad):
num = 0
while num < 3:
brad.forward(150)
brad.right(120)
brad.speed(1)
num += 1
def draw_arm(brad):
brad.forward(60)
brad.left(60)
brad.forward(60)
brad.backward(60)
brad.right(60)
brad.backward(60)
brad.right(60)
brad.forward(60)
brad.right(60)
brad.forward(60)
brad.backward(60)
brad.left(60)
brad.forward(90)
def draw_leg1(brad):
brad.left(120)
brad.forward(40)
brad.right(120)
brad.forward(120)
draw_foot1(brad)
def draw_leg2(brad):
brad.color("red")
brad.right(180)
brad.forward(120)
brad.right(60)
brad.forward(70)
brad.right(60)
brad.forward(120)
draw_foot2(brad)
def draw_foot1(brad):
brad.color("blue")
num = 0
while num < 4:
brad.forward(20)
brad.right(90)
num += 1
def draw_foot2(brad):
brad.color("blue")
num = 0
while num < 4:
brad.forward(20)
brad.left(90)
num += 1
draw_dream()
Output

Explanation:
- draw_dream(): Initializes the Turtle window and starts the drawing of the character.
- draw_Scarlett(): Creates the turtle and calls functions to draw different body parts.
- draw_head(brad): Draws the head as a circle.
- draw_body(brad): Draws the body using a triangle.
- draw_arm(brad) and draw_leg1(brad), draw_leg2(brad): Draw the arms and legs with specific angles and movements.
- draw_foot1(brad) and draw_foot2(brad): Draws square-shaped feet with blue color.
Related Articles:
Similar Reads
Python Tutorial | Learn Python Programming Language
Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio
10 min read
Python Interview Questions and Answers
Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Python OOPs Concepts
Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
Python Projects - Beginner to Advanced
Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions
Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs
Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Enumerate() in Python
enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam
3 min read
Python Data Types
Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read
Python Introduction
Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Python Lists
In Python, a list is a built-in dynamic sized array (automatically grows and shrinks). We can store all types of items (including another list) in a list. A list may contain mixed type of items, this is possible because a list mainly stores references at contiguous locations and actual items maybe s
6 min read