海龟三角形和用户输入。 python 3

turtle triangles, and user input. python 3

在向用户询问颜色后,我试图让它绘制一个三角形圆圈。三角形很好但填充黑色。我怀疑错误出在靠近底部的 "for i in range" 部分。

import turtle
def draw_triangle(side_length):#triangle def
    for x in range (3):
        turtle. left(120)
        turtle. forward(side_length)                   
    return None

def jump(distance):#jump definition
    turtle. penup()
    turtle. forward(distance)
    turtle. pendown()
    return None

def color_triangle(side_length, color):#makes the triangle color filled
    turtle. fillcolor()
    turtle. begin_fill()
    draw_triangle(size)
    turtle. end_fill()
    return None
color_a= input("choose a color for the first triangle ")
color_b= input ("choose a color for the second triangle ")
color_c= input("choose a color for the third triangle ")
back_color= input ("choose a color for the backround ")


my_colors= []

if color_a not in my_colors:
    my_colors . append (color_a)
if color_b not in my_colors:
    my_colors . append (color_b)
if color_c not in my_colors:
    my_colors . append (color_c)
color_number = 0
size= 75
move= 80
for i in range(10):
    the_color = my_colors[color_number]
    color_triangle(size, the_color)
    color_number= color_number +1
    if color_number >= len(my_colors):
        color_number=0
    jump(move)
    turtle. left (35)
turtle.bgcolor (back_color)

当您调用 turtle.fillcolor():

时,您没有使用 您的颜色

将您的 color_triangle 函数更新为:

def color_triangle(side_length, color):
    turtle.fillcolor(color)  # See here! Actually set the fill color!
    turtle.begin_fill()
    draw_triangle(size)
    turtle.end_fill()

documentation for fillcolor() 中注意,如果您不带参数调用它,它实际上 returns 当前填充颜色。在这种情况下,这不是您想要的。