Drawing a polygon in Python with a set of random colors
Question: 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

my code so far is:

    
    
    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()
    

I have found the problem in the code is with the "fillcolor = randomColor"

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

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


Answer: I am agree with the fact that you are choosing a random color with

    
    
    randomColor = random.randint(0,5)
    

but when you want to set the random color to your polygon

you specify an integer (value of randomColor variable) instead of a string
(value of fillcolor variable)

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

so may you please change the following line:

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

to

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

