2015-10-18 54 views
0

我試圖讓用戶在詢問用戶顏色後畫出一圈三角形。三角形出來很好,但填補了黑色。我懷疑這個錯誤是在底部附近的「我在範圍內」部分的某處。烏龜三角形和用戶輸入。 python 3

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) 
+0

我沒有看到任何「我在範圍內」。 ''後面請去除空格,謝謝。 – Maikflow

+0

向下滾動,其移動= 80後的一行開始 –

回答

0

您沒有使用你的顏色,當你調用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(),如果你不使用其它參數,它實際上返回當前的填充顏色。不是你想要的,在這種情況下。