有些颜色没有显示 - 海龟

我有一个呼吸描记器代码,可以使用给定的参数制作形状。当我运行代码时,只有白色和红色有效,蓝色和绿色仅显示为白色。


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

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


繁花不似锦
浏览 69回答 1
1回答

交互式爱情

您需要修复 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'您还可以使用列表来选择颜色:color='white'  # defaultcolorlst = ['white','blue','green','red']keylst = ['1','2','3','4']if color1 in keylst:    color=colorlst[keylst.index(color1)]
打开App,查看更多内容
随时随地看视频慕课网APP