Starting out with turtle graphics. I wanted to create a program that prints a certain number of squares, at a certain angle apart (number of squares and angles will vary based on user input). The flow will be -
- User inputs the number of squares
- User inputs the angle between each square
- Each square generated should have a different color
The problem with my code is actually in step 3. I created a function with a list of colors that would populate the color() method in turtle. However, the color() method always ends up fetching the last element in my list.
from turtle import *
##Function to populate the color() method from a list of predefined colors. color(i) always populates with 'red' when I run the code.
def chooseColor():
colorOption = ['orange', 'yellow', 'red']
for i in colorOption:
color(i)
#Function to create filled squares
def squareFill():
chooseColor()
begin_fill()
for i in range (4):
forward(100)
right(90)
end_fill()
#Function to create multiple squares
def multiSquare():
noOfsquares = int(input("How many squares do you want to print?:\n"))
angle = int(input("At what angle should the squares be from each other?:\n"))
for i in range (noOfsquares):
squareFill()
right(angle)
multiSquare()
I've zero clue about why color() only picks the last item in the list. Any help would be appreciated. Also, please pardon my messy code, still a noob. #TIA