15-110 PA8 Sample Solutions - Spring 2018 1. def score(hand): score = 0 ten_of_clubs = False for card in hand: if get_suit(card) == 2: if get_rank(card) == 12: score = score + 5 else: score = score + 1 if get_rank(card) == 10 and get_suit(card) == 3: score = score + 13 if get_rank(card) == 8 and get_suit(card) == 0: ten_of_clubs = True if get_rank(card) == 9 and get_suit(card) == 1: score = score - 11 if ten_of_clubs == True: score = score * 2 if score < 0: score = 0 return score 2. Answers will vary. 3. def checkerboard(): window = Tk() c = Canvas(window, width=600, height=600) c.pack() colors = ["black", "yellow"] for y in range(0,8): for x in range(0,8): squarecolor = colors[(x + y) % 2] c.create_rectangle(x*75,y*75,(x+1)*75,(y+1)*75,fill=squarecolor) window.mainloop() return None 4. def bargraph(datalist): # Assumption: list has exactly 10 data values window = Tk() c = Canvas(window, width=500, height=700) c.pack() colors = ["red", "green", "blue", "yellow", "cyan", "gray", "purple", "brown", "pink", "orange"] for i in range(0,10): width = datalist[i]*5 c.create_rectangle(0,70*i,width,70*(i+1),fill=colors[i]) window.mainloop() return None