Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 382: 11.3

Answer

code

Work Step by Step

# 11.3 (Sort students by grades) Rewrite Listing 11.2, GradeExam.py, to display the students # in increasing order of the number of correct answers. def main(): # Students' answers to the questions answers = [ ['A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'], ['D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'], ['E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'], ['C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'], ['A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'], ['B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'], ['B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'], ['E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D']] # Key to the questions keys = ['D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'] results = [] # Grade all answers for i in range(len(answers)): # Grade one student correctCount = 0 for j in range(len(answers[i])): if answers[i][j] == keys[j]: correctCount += 1 results.append([correctCount, "Student " + str(i)]) results.sort() for row in results: print(row[1], "correct count is", row[0]) main() # Call the main function
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.