Draw Square in Python Turtle

Hi developers, today you will see that how to draw a square from Turtle model in Python step by step. Python turtle allows you to direct different directions like rectangle, circle, cone and more. And turtle is an inbuilt Python Module. So to use it first of all you need some Python libraries to draw this square in python.

Draw Square in Python Turtle

So now let's see how you can Draw Square in Python Turtle with less code. So if you want to draw the square you can just copy the code given below and run it in your code editor to see the output.


You can also change the sideLength and angles to make changes in this. Now check two method to Draw Square in Python. And using this you can make it more interesting and enjoyable. Also I hope you will enjoy it. 


Let's see the code to Draw Square in Python Turtle

1. First Approach to Draw Square in Python Turtle

# Draw Square in Python Turtle
import turtle
t = turtle.Turtle()

sideLength = int(input("Enter the length of the side of the Square: "))

#drawing the first side of square
t.forward(sideLength) #Forward Turtle by sideLength units
t.left(90) #Turn turtle by 90 degree

#drawing the second side of square
t.forward(sideLength) #Forward Turtle by sideLength units
t.left(90) #Turn turtle by 90 degree

#drawing the third side of square
t.forward(sideLength) #Forward Turtle by sideLength units
t.left(90) #Turn turtle by 90 degree

#drawing the fourth side of square
t.forward(sideLength) #Forward Turtle by sideLength units
t.left(90) #Turn turtle by 90 degree

2. Second approach to Draw Square in Python Turtle

import turtle
#Set up the turtle screen
screen = turtle.Screen()
screen.title("Drawing Square in Python using Turtle")

# Creating a turtle name
drawSquare = turtle.Turtle()

# Increase the size of the square
sideLength = 100

# Draw a square
for _ in range(4):
  drawSquare.forward(sideLength)
  drawSquare.left(90)

# Keep the window open until closed by the user
turtle.done()


Conclusion

I hope this article will be helpful for you and you will be able to Draw Square in Python Turtle. If you found this article is helpful for you then please drop a comment below and I will share more articles on python for you. Happy Coding!

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad