从 turtle 的图形开始.我想创建一个程序,以一定的Angular 打印一定数量的方块(方块和Angular 会根据用户输入的不同而有所不同).流量将会是-
- 用户输入正方形的数量
- 用户输入每个方块之间的Angular
- 生成的每个正方形应该有不同的 colored颜色
我的代码的问题实际上是在步骤3中.我创建了一个带有 colored颜色 列表的函数,该函数将填充Turtle中的color()方法.然而,color()方法总是以获取列表中的最后一个元素结束.
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()
我不知道为什么COLOR()只 Select 列表中的最后一项.任何帮助都将不胜感激.另外,请原谅我乱七八糟的代码,仍然是个菜鸟.#TIA