# Draw Shape inside Shape in Python Using Turtle

• Difficulty Level : Medium
• Last Updated : 16 Sep, 2021

Prerequisites: Turtle Programming in Python

Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes in the turtle library. The turtle module can be used in both object-oriented and procedure-oriented ways.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Some of the commonly used methods which are also used here are:

• forward(length): moves the pen in the forward direction by x unit.
• backward(length): moves the pen in the backward direction by x unit.
• right(angle): rotate the pen in the clockwise direction by an angle x.
• left(angle): rotate the pen in the anticlockwise direction by an angle x.
• penup(): stop drawing of the turtle pen.
• pendown(): start drawing of the turtle pen.

In this article, we will draw various shape inside a similar shape like drawing triangles inside triangle.

## Triangle inside Triangle

• Define an instance for turtle.
• For a square execute a loop 3 times (sides).
• In every iteration move turtle 120 units forward.
• This will make up a Triangle.
• This is made multiple times to form triangles inside the triangle using a function.

Below is the python implementation.

## Python3

 `# import the turtle modules``import` `turtle`  `# define the function``# for triangle``def` `form_tri(side):``    ``for` `i ``in` `range``(``3``):``        ``my_pen.fd(side)``        ``my_pen.left(``120``)``        ``side ``-``=` `10` `        ` `# Forming the window screen``tut ``=` `turtle.Screen()``tut.bgcolor(``"green"``)``tut.title(``"Turtle"``)` `my_pen ``=` `turtle.Turtle()``my_pen.color(``"orange"``)` `tut ``=` `turtle.Screen()          ` `# for different shapes``side ``=` `300``for` `i ``in` `range``(``10``):``    ``form_tri(side)``    ``side ``-``=` `30`

Output : ## Square inside Square

• Define an instance for turtle.
• For a square execute a loop 4 times (sides).
• In every iteration move turtle 90 units forward.
• This will make up a Square.
• This is made multiple times to form squares inside squares using a function.

Below is the python implementation.

## Python3

 `# import the turtle modules``import` `turtle` `# define the function``# for square``def` `form_sq(side):``    ``for` `i ``in` `range``(``4``):``        ``my_pen.fd(side)``        ``my_pen.left(``90``)``        ``side ``-``=` `5` `        ` `# Forming the window screen``tut ``=` `turtle.Screen()``tut.bgcolor(``"green"``)``tut.title(``"Turtle"``)` `my_pen ``=` `turtle.Turtle()``my_pen.color(``"orange"``)` `tut ``=` `turtle.Screen()          ` `# for different shapes``side ``=` `200` `for` `i ``in` `range``(``10``):``    ``form_sq(side)``    ``side``-``=` `20`

Output : ## Hexagon inside Hexagon

• Define an instance for turtle.
• For a hexagon execute a loop 6 times (sides).
• In every iteration move turtle 300 units forward.
• This will make up a Hexagon.
• This is made multiple times to form hexagons inside the hexagon using a function.

Below is the python implementation.

## Python3

 `# import the turtle modules``import` `turtle`  `# define the function``# for hexagon``def` `form_hex(side):``    ``for` `i ``in` `range``(``6``):``        ``my_pen.fd(side)``        ``my_pen.left(``300``)``        ``side ``-``=` `2`  `# Forming the window screen``tut ``=` `turtle.Screen()``tut.bgcolor(``"green"``)``tut.title(``"Turtle"``)` `my_pen ``=` `turtle.Turtle()``my_pen.color(``"orange"``)` `tut ``=` `turtle.Screen()` `# for different sizes``side ``=` `120` `for` `i ``in` `range``(``5``):``    ``form_hex(side)``    ``side ``-``=` `12`

Output : My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.67388076,"math_prob":0.75122654,"size":3526,"snap":"2021-43-2021-49","text_gpt3_token_len":906,"char_repetition_ratio":0.1306076,"word_repetition_ratio":0.36528927,"special_character_ratio":0.26347136,"punctuation_ratio":0.12908243,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9818101,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-07T16:29:59Z\",\"WARC-Record-ID\":\"<urn:uuid:f062c521-d160-4196-9af6-5ae7b7a52f92>\",\"Content-Length\":\"128394\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8b4146c4-f22c-4984-9285-86ec9b4ecc11>\",\"WARC-Concurrent-To\":\"<urn:uuid:957bb651-e331-4c34-aa95-3d2beedc51a8>\",\"WARC-IP-Address\":\"23.218.217.150\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/draw-shape-inside-shape-in-python-using-turtle/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:5P2ZQKDVUXFT7VB5JY2OTQ6MIDZKBDGN\",\"WARC-Block-Digest\":\"sha1:ZCAXE55Y65VAQ5D5YYV4XJ2LO4MPO2UU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363400.19_warc_CC-MAIN-20211207140255-20211207170255-00025.warc.gz\"}"}