[5 pts] Write the function studentGrades(gradeList) that takes a nested list wit
ID: 3744193 • Letter: #
Question
[5 pts] Write the function studentGrades(gradeList) that takes a nested list with the following structure: First list is always a descriptive header. -Subsequent lists hold all the data For lists that hold data, the first element is always a string, the rest of the elements are numeric values. Each list (except for the first one) represents the grades of the student and the first element of each list contains the name of the student. grades - [ [ ' student', 'Quiz 1', 'Quiz 2', 'Quiz 3'],# List 1, header ["John', 100, 90, 80], [ 'McVay', 88, 99, 111], ['Rita', 45, 56, 67], ['Ketan', 59, 61, 671, 'Saranya', 73, 79, 831, [ 'Min', 89, 97, 101]] and returns ONE list with the average score for each student in INTEGER format. Hint: The method sum adds all the numeric elements of a list (sum([1,2,8.1]) returns 11.1). grades [ ["Student', "Quiz 1', "Quiz 2", "Quiz 3'], ["John', 100, 90, 80], 'McVay', 88, 99, 111], ['Rita', 45, 56, 67], [ 'Ketan', 59, 61, 67], 100 + 90 80 270 270/3 - 90 Saranya', 73, 79, 831 [ 'Min', 89, 97, 101]] >>>studentGrades (grades) [90,99,56, 62, 78,95]Explanation / Answer
def studentGrades(grades): lst = [] for i in range(1, len(grades)): total = 0 count = 0 for j in range(1, len(grades[i])): total += grades[i][j] count += 1 lst.append(total // count) return lst grades = [ ['Student', 'Quiz 1', 'Quiz 2', 'Quiz 3'], ['John', 100, 90, 80], ['McVay', 88, 99, 111], ['Rita', 45, 56, 67], ['Ketan', 59, 61, 67], ['Saranya', 73, 79, 83], ['Min', 89, 97, 101]] print(studentGrades(grades))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.