Introduction
Python has a built-in module called turtle. It allows us to draw any drawing using a turtle and the turtle module's methods, as well as some logical loops. The four methods offered in the turtle module are used to create turtle drawings. It 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. In this article, we'll look at how to use the Turtle module to create various shaped Polygons. Any polygon shape can be simply drawn given the number of sides (x) and length of sides (l). Let's look at some examples to assist us to grasp it better.
Also see, Merge Sort Python, Fibonacci Series in Python
Steps to draw a Polygon turtle
Approach
-
Import a turtle and create an object from it.
-
You may take the number of sides(x) and length(l) of the polygon by the user or by yourself.
-
Iterate the loop for x times.
- Move forward turtle l length and turn it 360/x degree.
Code
# draw any polygon in turtle
# import turtle
import turtle
# creating turtle object
ob = turtle.Turtle()
# Accepting the number of sides of the polygon as input
x = int(input("Enter the number of sides of the polygon"))
# Accepting the number of sides of the polygon as input
l = int(input("Enter the length of sides of the polygon"))
for _ in range(x):
turtle.forward(l)
turtle.right(360/x)
Input
8
100
Output

Input
4
100
Output

Input
3
100
Output

You can practice by yourself with the help of online python compiler for better understanding.
You can also read about Palindrome Number in Python here.
Check out Escape Sequence in Python




