def isBalanced(list, pivot): +5 points header """return True if list is balanced w.r.t pivot; False otherwise""" +2 if has documentation and uses 'return' in it numSmaller = numLarger = 0 +1 for some variable for totaling for element in list: +3 for loop with ":" at end if element < pivot: +1 deal with elements smaller numSmaller = numSmaller + 1 +1 increment total (either small or large) elif element > pivot: +1 deal with elements larger numLarger = numLarger + 1 return numSmaller == numLarger +1 return +1 correct result -------------------------------------------------------------------------------- def simNGames (numGames, probA, probB): +6 header """Simulat N games of RQ and return winsA, winsB" +2 documentation with 'return' and 'tuple' winsA = winsB = 0 +1 total of wins trials = 0 while trials < numGames: +3 for way to deal with trials scoreA, scoreB = simOneGame(probA, +1 for invoking and getting both probB) if scoreA > scoreB: +2 for condition and increment winsA = winsA + 1 if scoreB > scoreA: winsB = winsB + 1 +2 for condition and increment return winsA, winsB +1 for return +1 for tuple -------------------------------------------------------------------------------- Q4: Each question is worth six points A) [8, 3, 12, 3, 3] is worth +6 [8, ?, ?, ?, 3] is worth +2 [?, 3, 12, 3, ?] gets other +4 points B) [8, 3, 12, 3] gets +6 [8, ?, ?, 3] gets +2 [?, 3, 12, ?] gets +4 C) [5, 1, 4] gets +6 [5, ?, 4] gets +3 [?, 1, ?] gets +3