All pastes #886651 Raw Edit

Untitled

public python v1 · immutable
#886651 ·published 2008-01-31 20:49 UTC
rendered paste body
from graphics import *def main():    across, down = getInput()    colours = colour()    format(across, down, colours)    def getInput():    across = input ("Enter number of columns: ")    while True:         if across <= 8 and across >= 2 and across == int(across): break         across = input ('Invaild number ')    down = input ("Enter number of rows: ")    while True:         if down <= 8 and down >= 2 and down == int(down): break         down = input ('Invaild number ')         return int(across), int(down)def colour():    choice = ['red', 'green', 'blue', 'magenta', 'yellow', 'cyan']    counter, colours = 0, []       print 'Enter 3 different colours'    while True:        print 'Colour', counter + 1, choice        colour = raw_input('Enter a colour: ')        colour = colour.lower()        if colour in choice:            colours.append(colour)            choice.remove(colour)            counter = counter + 1        else:            print 'the colour is not valid'        if counter == 3:            break    return coloursdef format(down, across, colours):    win = GraphWin("patchwork", across * 100, down * 100)    colour, y = colours[0], 1    for a in range(down):        x=0        for b in range(across):            if (a + b) % 2 == 0:                  patch8(win, x, y, colour)            else:                patch0(win, x, y, colour)            x, = x+100,            if colour==colours[0]:                colour=colours[1]            elif colour==colours[1]:                colour=colours[2]            else:                colour=colours[0]        y=y+100        def patch8(win, x, y, colour):    for i in range(10):        rectangle=Rectangle(Point(x+0+i*10,y+10+i*10),Point(x+10+i*10,y+0+i*10))        rectangle.setFill(colour)        rectangle.draw(win)    largeBox = Rectangle(Point(x, y),                         Point(x + 100, y + 100))    largeBox.draw(win)def patch0(win,x,y,colour):    for i in range(10):        rectangle=Rectangle(Point(x+10+i*10,y+0+i*10),Point(x+0+i*10,y+10+i*10))        rectangle.setFill(colour)        rectangle.draw(win)    largeBox = Rectangle(Point(x, y),                         Point(x + 100, y + 100))    largeBox.draw(win)    main()