CS365 Final Answers -- Spring 2016


    1. menu/list (b)
    2. radio button (d)
    3. check box (e)
    4. text box (c)
    5. slider (a)
  1. d
  2. b
  3. c
  4. d
  5. c
  6. a
  7. c
  8. c, e
  9. a, c, d, h, i
  10. a, c, d
  11. 2
  12. a
  13. b
  14. a, d, h, j, l
  15. a, c
  16. b, d, g
  17. def countVotes(ballots):
      voters = {}
      candidates = {}
      for voter, candidate in ballots:
        # make sure vote has not already voted
        if (voter not in voters):
          voters[voter] = True
    
          # if this is the first vote for a candidate, initialize
          # the candidate's vote total to 0
          if candidate not in candidates:
    	candidates[candidate] = 0
          candidates[candidate] += 1
      finalists = sorted(candidates.iteritems(), key=itemgetter(1), reverse=True)
      for candidate, votes in finalists:
          print candidate, votes