0
안녕하세요 저는 행, 열, 정사각형 길이 및 세 가지 색상 수에 대해 사용자로부터 입력을받는 프로그램을 파이썬으로 작성해야합니다. 그런 다음 프로그램은 행과 열의 수에 따라 그리드를 만들고 교차 체크 무늬 패턴으로 사각형을 채 웁니다. 색상으로 채워지는 지점까지 코드화했습니다. 누구든지 저를 도울 수 있는지 궁금합니다. 여기 내가 지금까지 가지고있는 것입니다 :Python turtle color
from turtle import *
t = Turtle()
screen = t.getscreen()
rows = screen.numinput('Number of rows',
'How many rows shall there be?', 5, 1, 10)
columns = screen.numinput('Number of columns',
'How many columns shall there be?', 5, 1, 10)
side_length = screen.numinput('Length of square side',
'How long shall the square sides be?', 30, 10, 50)
first_color = screen.textinput('First color',
'What shall the first color be?')
second_color = screen.textinput('Second color',
'What shall the second color be?')
third_color = screen.textinput('Third color',
'What shall the third color be?')
square_color = ''
def draw_square():
t.begin_fill()
t.pendown()
t.forward(side_length)
t.left(90)
t.forward(side_length)
t.left(90)
t.forward(side_length)
t.left(90)
t.forward(side_length)
t.color(square_color)
t.end_fill()
t.penup()
t.color('black')
t.left(90)
t.forward(side_length)
def draw_board():
n = 1
for i in range(int(columns)):
draw_square()
for x in range(int(rows - 1)):
t.goto(0,side_length * n)
for i in range(int(columns)):
draw_square()
n += 1
for i in range(int(columns)):
for x in range(int(rows)):
if x + i % 3 == 0:
square_color = first_color
elif x + i % 3 == 1:
square_color = second_color
elif x + i % 3 == 2:
square_color = third_color
draw_board()
done()
당신이 궁금해 아래 코드 내 재 작업이 어떤 스타일의 개조하면 되겠 어 및 코드 정리와 함께 더 나은 위해 물건을 넣어하는 것입니다 뭐라구? 귀하의 질문은 무엇인가? – TigerhawkT3
@ TigerhawkT3 사용자가 질문 할 때 매우 분명합니다. 질문의 어느 부분을 이해하는 데 도움이 필요합니까? – nehemiah
@itsneo - 매우 분명하다면 나와 공유하십시오. 질문은 무엇입니까? "누군가가 나를 위해이 프로그램을 끝내고 완성 할 수 있었습니까?" 질문이 아닙니다. – TigerhawkT3