dpolygonnw.py

Created by ews31415

Created on February 19, 2023

570 Bytes

Draws a regular polygon


from math import *
from turtle import *

# initialization
s=60
n=int(input("# of sides? "))

# angle
a=180*(n-2)/n

# set color numworks
k=-1
l=['blue','red','green','orange','purple']
while k<0 or k>4:
  print("Choose Color")
  print("0. blue")
  print("1. red")
  print("2. green")
  print("3. orange")
  print("4. purple")
  k=int(input())
col=l[k]

# setup
penup()
left(180)
forward(60)
left(90)
forward(60)
left(90)

# draw the polygon
pendown()
color(col)
for i in range(n):
  if n>6:
    forward(s/2)
  else:
    forward(s)
  left(180-a)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.