有些颜色没有显示 - 乌龟

Some colors are not showing - turtle

我有一个螺旋图代码,可以根据给定的参数生成一个形状。当我 运行 代码时,只有白色和红色起作用,而蓝色和绿色只显示为白色。

print('Choose a color: ')
print('1. White')
print('2. Blue')
print('3. Green')
print('4. Red')
color1 = input('-')

那部分要求你想要的颜色

if color1 == '1':
    color = 'white'
if color1 == '2':
    color = 'blue'
if color1 == '3':
    color = 'green'
if color1 == '4':
    color = 'red'
elif color1 != '1' or '2' or '3' or '4':
    color = 'white'

该部分将输入转换为颜色

    draw = True
    t.speed(0)
    num = 0
    t.hideturtle()
    t.pencolor(color) #this part right here
    while draw == True:
        t.circle(90)
        t.rt(rotate)
        num += 1
        if num >= lines:
            draw = False
            print('Press enter to draw again!')
            continue

这是将海龟颜色声明为您想要的颜色的绘图循环的一部分。

您需要修复您的 if / else 块:

if color1 == '1':
    color = 'white'
elif color1 == '2':
    color = 'blue'
elif color1 == '3':
    color = 'green'
elif color1 == '4':
    color = 'red'
else:
    color = 'white'

您还可以使用列表来 select 颜色:

color='white'  # default
colorlst = ['white','blue','green','red']
keylst = ['1','2','3','4']
if color1 in keylst:
    color=colorlst[keylst.index(color1)]