draw polygon based on user input - turtle python

0 votes
I'm trying to write a turtle code to ask the user how many sides polygon they would like. How do I do that?
Jul 5, 2019 in Python by Yamini
820 views

1 answer to this question.

0 votes

Try something like this:

import turtle
# create a screem
window = turtle.Screen()
#Set the background color
window.bgcolor("lightgreen")
#create turtle
turtle = turtle.Turtle()
# set turtle color
turtle.color("blue")
turtle.pensize(3)
# take input
sides = int(input("How many sides do you want? Use digits: "))
polygon(sides, length)
def polygon(sides,length):
    for x in range(sides):
        shape.forward(length)
        shape.left(360/sides)
answered Jul 5, 2019 by Umer

Related Questions In Python

0 votes
1 answer

Unable to take input from user in Python

num = input("enter number") print(num) READ MORE

answered May 1, 2018 in Python by aayushi
• 750 points
55 views
0 votes
1 answer

Draw a square using the turtle module - Python

Hey @Baily, use something like this: import turtle sq ...READ MORE

answered Jun 21, 2019 in Python by Himanshu
112 views
0 votes
1 answer

How do I draw a hexagon using the turtle module of python?

Hey @Jinu, try this: import turtle polygon = ...READ MORE

answered Jun 23, 2019 in Python by Haseeb
560 views
+1 vote
2 answers

Measuring the distance between pixels on OpenCv with Python

You can try this: Mat pts1(nPts, 1, CV_8UC2), ...READ MORE

answered Aug 24, 2018 in Python by Omkar
• 68,860 points
3,979 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 534 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

Snake head placed on the center - Python using turtle

You can use turtle's goto() function. This ...READ MORE

answered Jun 21, 2019 in Python by Greg
73 views
0 votes
1 answer

How do I draw a semi-circle only using turtle - Python

Try this: import turtle turtle = turtle.Pen() turtle.left(90) for x in ...READ MORE

answered Jul 5, 2019 in Python by Bheem
757 views