The following code should allow a user to specify the number of sides of a polygon, and the code should draw a polygon of the appropriate construction on the turtle screen. Unfortunately, there are several errors in this code.
# Import the turtle package for drawing
import turtle
# Create a screen on which we draw
screen = turtle.Screen()
# Configure a default size
dimX = 400
dimY = 400
screen.setup(dimX, dimY)
numSides = int(input("How many sides do you want in your polygon? "))
print("Sides you requested:", numSides)
# Reset the screen (this code is good)
turtle.clearscreen()
screen.reset()
screen.screensize(dimX, dimY)
ttl = turtle.Turtle()
ttl.penup()
ttl.setposition(0, -150)
ttl.pendown()
ttl.speed(9) # Make tracing fast
# Constant side length
sideLength = 100
## CORRECT THE CODE BELOW
if ( sideLength > -1 ):
interiorAngle = (numSides - 2) * 180 / numSides
print("Each angle:", interiorAngle)
for i in range(0, numSides):
ttl.forward(sideLength)
ttl.left(180-interiorAngle)
else:
print("Invalid number of sides")
turtle.done()