I have this Python program that prints out colors from a predefined list called "UserColorIndex" - I want the program printing those colors depending of the number value for the variable called "NumberOfCircles." So if there were 100 in the value for the NumberOfCircles, then the program should print out those colors from the list 100 times, and if the index is only 9 colors, then the program should loop through those colors and repeat through those colors to get them printed. I tried using the enumerate method but that just created a different data type. How would I fix/do this?
Here is my code:
NumberOfCircles = 18 # I don't know, just some random number, the program should work regardless of which number is placed
def GenerateRosette():
for i in range(NumberOfCircles):
print(UserColorIndex[i])
UserColorIndex = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet", "Black", "Grey"]
GenerateRosette()
Output:
________________
Red
Orange
Yellow
Green
Blue
Indigo
Violet
Black
Grey
Traceback (most recent call last):
File "file.py", line 9, in <module>
GenerateRosette()
File "file.py", line 5, in GenerateRosette
print(UserColorIndex[i])
IndexError: list index out of range
EXPECTED Output (What I want):
________________
Red
Orange
Yellow
Green
Blue
Indigo
Violet
Black
Grey
Red
Orange
Yellow
Green
Blue
Indigo
Violet
Black
Grey
In the expected output, I want the list to be printed depending on how many times the for loop was run (NumberOfCircles). I want it to loop through the list. How would I do this?
whileseems easier.