def makeModel(data):
    data["r"] = 100
    data["color"] = "red"

def makeView(data, canvas):
    canvas.create_oval(
        200 - data["r"], 200 - data["r"],
        200 + data["r"], 200 + data["r"],
        fill=data["color"])

def keyPressed(data, event):     
    if event.keysym == "Up":
        data["r"] += 10
    elif event.keysym == "Down":
        data["r"] -= 10 

def runRules(data, call):
    if data["color"] == "red":
        data["color"] = "blue"
    else:
        data["color"] = "red"

def mousePressed(data, event):
    # Use event.x and event.y to get the (x,y) location of the clicked pixel
    pass

# You do not need to be able to write the following functions;
# just modify the five functions above.

from tkinter import *

def timeLoop(data, canvas, call):
    runRules(data, call)

    canvas.delete(ALL)
    makeView(data, canvas)
    canvas.update()

    canvas.after(data["timeRate"], timeLoop, data, canvas, call + 1)

def keyEventHandler(data, canvas, event):
    keyPressed(data, event)
    
    canvas.delete(ALL)
    makeView(data, canvas)
    canvas.update()
    
def mouseEventHandler(data, canvas, event):
    mousePressed(data, event)
    
    canvas.delete(ALL)
    makeView(data, canvas)
    canvas.update()
    
def runSimulation(w, h, timeRate):
    data = { }
    data["timeRate"] = int(timeRate * 1000) # call will be in ms
    makeModel(data)
    
    root = Tk()
    canvas = Canvas(root, width=w, height=h)
    canvas.configure(bd=0, highlightthickness=0)
    canvas.pack()
    makeView(data, canvas)
    
    canvas.after(data["timeRate"], timeLoop, data, canvas, 1)
    
    root.bind("<Key>", lambda event : keyEventHandler(data, canvas, event))
    root.bind("<Button-1>", lambda event : mouseEventHandler(data, canvas, event))
    
    root.mainloop()

runSimulation(400, 400, 0.1)

###

books = [ ["title", "genre", "pages", "price"],
          ["The Hobbit", "fantasy", "310 pages", "$12.99"],
          ["1984", "dystopian", "328 pages", "$15.50"],
          ["Dune", "sci-fi", "688 pages", "$11.99"],
          ["The Name of the Wind", "fantasy", "662 pages", "$16.99"],
          ["Neuromancer", "sci-fi", "271 pages", "$18.75"],
          ["Mistborn", "fantasy", "295 pages", "$11.25"] ]

def findBooks(books, genre, pages, price):
    result = [ ]
    for i in range(1, len(books)):
        entry = books[i]
        if genre == entry[1]:
            num = int(entry[2][:len(entry[2]) - len(" pages")])
            if num < pages:
                tmp = float(entry[3][1:])
                if tmp <= price:
                    result.append(entry[0])
    
    return result
    
assert(findBooks(books, "fantasy", 350, 13.00) == ["The Hobbit", "Mistborn"])
assert(findBooks(books, "sci-fi", 300, 15.00) == [ ])

###

"""
makeBoard(), takes no input and returns a 2D list representation of the board
displayBoard(board), takes the 2D list representation of the board and displays it
makeMove(board, player), takes the 2D list representation of the board and the current player (either "red" or "blue"), gets a valid move from the player, applies that move to the board, and returns the updated board
isGameOver(board), takes the 2D list representation of the board and returns True if the game is over and False otherwise
"""

def playGame():
    # set up board
    # choose players
    # take turns - I go, you go, I go, etc
    # stop when the game is over
    
    board = makeBoard()
    displayBoard(board)
    player = "red"
    
    while not isGameOver(board):
        board = makeMove(board, player)
        displayBoard(board)
        
        if player == "red":
            player = "blue"
        else:
            player = "red"