# Draw Square and Rectangle in Turtle – Python

Prerequisite: Turtle Programming Basics

turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e `forward()`, `backward()`, etc.

## Drawing Square:

 `# draw square in Python Turtle ` `import` `turtle ` `  `  `t ``=` `turtle.Turtle() ` ` `  `s ``=` `int``(``input``(``"Enter the length of the side of the Squre: "``)) ` ` `  `# drawing first side ` `t.forward(s) ``# Forward turtle by s units ` `t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `# drawing second side ` `t.forward(s) ``# Forward turtle by s units ` `t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `# drawing third side ` `t.forward(s) ``# Forward turtle by s units ` `t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `# drawing fourth side ` `t.forward(s) ``# Forward turtle by s units ` `t.left(``90``) ``# Turn turtle by 90 degree `

Input :

`100`

Output : Second approach (Using Loop) :

 `# draw Squre in Python Turtle ` `import` `turtle ` `  `  `t ``=` `turtle.Turtle() ` ` `  `s ``=` `int``(``input``(``"Enter the length of the side of squre: "``)) ` ` `  `for` `_ ``in` `range``(``4``): ` `  ``t.forward(s) ``# Forward turtle by s units ` `  ``t.left(``90``) ``# Turn turtle by 90 degree `

Input :

`100`

Output : ## Drawing Rectangle:

 `# draw Rectangle in Python Turtle ` `import` `turtle ` `  `  `t ``=` `turtle.Turtle() ` ` `  `l ``=` `int``(``input``(``"Enter the length of the Rectangle: "``)) ` `w ``=` `int``(``input``(``"Enter the width of the Rectangle: "``)) ` ` `  `# drawing first side ` `t.forward(l) ``# Forward turtle by l units ` `t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `# drawing second side ` `t.forward(w) ``# Forward turtle by w units ` `t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `# drawing third side ` `t.forward(l) ``# Forward turtle by l units ` `t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `# drawing fourth side ` `t.forward(w) ``# Forward turtle by w units ` `t.left(``90``) ``# Turn turtle by 90 degree `

Input :

```100
120```

Output : Second approach (Using Loop) :

 `# draw Rectangle in Python Turtle ` `import` `turtle ` `  `  `t ``=` `turtle.Turtle() ` ` `  `l ``=` `int``(``input``(``"Enter the length of the Rectangle: "``)) ` `w ``=` `int``(``input``(``"Enter the width of the Rectangle: "``)) ` ` `  `for` `_ ``in` `range``(``4``): ` `   `  `  ``# drawing length ` `  ``if` `_``%` `2` `=``=` `0``: ` `    ``t.forward(l) ``# Forward turtle by l units ` `    ``t.left(``90``) ``# Turn turtle by 90 degree ` ` `  `  ``# drawing width ` `  ``else``: ` `    ``t.forward(w) ``# Forward turtle by w units ` `    ``t.left(``90``) ``# Turn turtle by 90 degree `

Input :

```100
120```

Output : My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.