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 in Python by Yamini
52 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 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
31 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 in Python by Himanshu
66 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 in Python by Haseeb
75 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
• 67,380 points
2,774 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 216 views
+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 in Python by Greg
49 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 in Python by Bheem
61 views