Drawing a polygon in Python with a set of random colors
<p>I am working on a simple python program which prompts the user to enter the length of the side of a polygon and the program (using turtle) will draw the polygon with a random color that has been set using the random.randint</p>

<p>my code so far is:</p>

<pre><code>import turtle

polygonSideLength = int(input('Enter length of polygon side: \n'))
numberOfSides = 5 + (7 / 4)
turnAngle = 360 / numberOfSides

import random
randomColor = random.randint(0,5)
if randomColor == 0:
    fillcolor="red"
elif randomColor == 1:
    fillcolor="green"
elif randomColor == 2:
    fillcolor="blue"
elif randomColor == 3:
    fillcolor="cyan"
elif randomColor == 4:
    fillcolor="magenta"
elif randomColor == 5:
    fillcolor="yellow"


turtle.begin_fill()
turtle.pen(pensize = 5, pencolor="black", fillcolor = randomColor)

for i in range(numberOfSides):
    turtle.forward(polygonSideLength)
    turtle.right(turnAngle)
turtle.end_fill()
turtle.done()
</code></pre>

<p>I have found the problem in the code is with the "fillcolor = randomColor"</p>

<p>the error I receive is "unknown color name for: 5" 
I know the randint is working because sometimes the error gives me 1,2,3,4,5</p>

<p>So to sum it up, how do I get the fillcolor to match the set colors in the random randint?</p>

<p>I am agree with the fact that you are choosing a random color with</p>

<pre><code>randomColor = random.randint(0,5)
</code></pre>

<p>but when you want to set the random color to your polygon</p>

<p>you specify an integer (value of randomColor variable) instead of a string  (value of fillcolor variable)</p>

<p>fillcolor variable is expected to be a string type with a color name value ( "blue","white","red", etc) but never an integer.</p>

<p>so may you please change the following line:</p>

<pre><code>turtle.pen(pensize = 5, pencolor="black", fillcolor = randomColor)
</code></pre>

<p>to</p>

<pre><code>turtle.pen(pensize = 5, pencolor="black", fillcolor = fillcolor)
</code></pre>

python