【问题标题】:Setting turtle colour设置海龟颜色
【发布时间】:2021-10-05 05:11:55
【问题描述】:

我想问“选择你的笔颜色(红色、橙色、黄色、绿色或蓝色):” 并根据他们的选择改变乌龟笔的颜色。到目前为止,这是我的台词:

    colors = ["red", "orange", "yellow", "green", "blue"]
    color = input ("Please choose your color (red, orange, yellow, green, blue): ")
    color = choice.colors
    turtle.color (color)

系统说“选择”没有定义。我该如何解决?

【问题讨论】:

    标签: python turtle-graphics


    【解决方案1】:

    random.choice() 函数用于您希望计算机随机选择一种颜色。由于您让您的用户决定,我们不需要它:

    import turtle
    
    COLORS = ['red', 'orange', 'yellow', 'green', 'blue']
    
    color = input("Please choose your color ({}): ".format(', '.join(COLORS)))
    
    turtle.color(color)
    
    turtle.done()
    

    【讨论】: