2016-10-21 4 views
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() 
+0

당신이 궁금해 아래 코드 내 재 작업이 어떤 스타일의 개조하면 되겠 어 및 코드 정리와 함께 더 나은 위해 물건을 넣어하는 것입니다 뭐라구? 귀하의 질문은 무엇인가? – TigerhawkT3

+0

@ TigerhawkT3 사용자가 질문 할 때 매우 분명합니다. 질문의 어느 부분을 이해하는 데 도움이 필요합니까? – nehemiah

+0

@itsneo - 매우 분명하다면 나와 공유하십시오. 질문은 무엇입니까? "누군가가 나를 위해이 프로그램을 끝내고 완성 할 수 있었습니까?" 질문이 아닙니다. – TigerhawkT3

답변

1

당신은 필요한 코드를 모두 가지고 있습니다. 너는 그것을 올바르게 조립하지 않았을 뿐이다. 당신은 당신의 프로그램을 이야기로 생각해야하고 이야기가 올바른 순서로 이야기가되어 이야기가 이치에 맞아야합니다.

from turtle import Turtle, Screen 

def draw_square(turtle, length, color): 
    turtle.color(color) 
    turtle.pendown() 

    turtle.begin_fill() 
    for _ in range(4): 
     turtle.forward(length) 
     turtle.left(90) 
    turtle.end_fill() 

    turtle.penup() 
    turtle.forward(length) 

def draw_board(turtle, length, colors): 
    n = 0 

    for row in range(int(rows)): 
     turtle.goto(0, length * n) 
     for column in range(int(columns)): 
      square_color = colors[(column + row) % len(colors)] 
      draw_square(turtle, length, square_color) 
     n += 1 

screen = Screen() 

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 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?') 

colors = [first_color, second_color, third_color] 

turtle = Turtle() 
turtle.penup() 

draw_board(turtle, side_length, colors) 

turtle.hideturtle() 

screen.exitonclick() 

가 생산 : 누군가가 당신을 도울 수 있다면

enter image description here