Поскольку вы пометили свой вопрос [python-3.x], вместо того, чтобы запрашивать цвет в окне консоли, я предлагаю вам использовать собственный виджет ввода текста черепахой, новый в Python 3:
>>> help(turtle.textinput)
Help on function textinput in module turtle:
textinput(title, prompt)
Pop up a dialog window for input of a string.
Arguments: title is the title of the dialog window,
prompt is a text mostly describing what information to input.
Return the string input
If the dialog is canceled, return None.
Example:
>>> textinput("NIM", "Name of first player:")
>>>
Вот пример, который делает именно это.Он использует try ... except
в цикле, чтобы снова запросить цвет, если пользователь вводит какой-то цвет, который он не знает, например, «козлик».Как только они выбирают правильный цвет, отличный от первоначального «черного» по умолчанию, он продолжает рисовать круг в этом новом цвете:
import turtle
while turtle.pencolor() == 'black':
try:
color = turtle.textinput("Color", "Enter the pen color:")
turtle.pencolor(color)
except turtle.TurtleGraphicsError:
pass
turtle.penup()
turtle.sety(-100)
turtle.pendown()
turtle.width(10)
turtle.circle(100)
turtle.hideturtle()
turtle.done()