Ana sayfa
/
Teknoloji
/
Part 3 (40pts) Write a Python function colculoteAveroges() that takes a list of tuples as parameter. Each contains a student name (string) and a list of their test scores (list of integers). The function s return a list of tuples, where each tuple contains a student's name and his/her average test score. Write Python statements that create a list of tuples containing student names and their scores (a: in the sample run below), print this list call the above mentioned function and print the averages Part 3:

Soru

Part 3 (40pts)
Write a Python function colculoteAveroges() that takes a list of tuples as parameter. Each
contains a student name (string) and a list of their test scores (list of integers). The function s
return a list of tuples, where each tuple contains a student's name and his/her average test score.
Write Python statements that create a list of tuples containing student names and their scores (a:
in the sample run below), print this list call the above mentioned function and print the averages
Part 3:

Part 3 (40pts) Write a Python function colculoteAveroges() that takes a list of tuples as parameter. Each contains a student name (string) and a list of their test scores (list of integers). The function s return a list of tuples, where each tuple contains a student's name and his/her average test score. Write Python statements that create a list of tuples containing student names and their scores (a: in the sample run below), print this list call the above mentioned function and print the averages Part 3:

Çözüm

3.5267 Voting
avatar
Ebru
Usta · 5 yıl öğretmeni
Uzman doğrulaması

Cevap

Here is an example implementation of the `calculateAverages()` function in Python:<br />```python<br />def calculateAverages(students):<br /> averages = []<br /> for student in students:<br /> total = sum(student[1])<br /> average = total / len(student[1])<br /> averages.append((student[0], average))<br /> return averages<br />```<br />This function takes a list of tuples as input, where each tuple contains a student's name (as a string) and a list of their test scores (as a list of integers). The function calculates the average test score for each student by summing their test scores and dividing by the number of test scores. The function then returns a list of tuples, where each tuple contains a student's name and their average test score.<br /><br />Here is an example of how to use this function to calculate the average test scores for a list of students:<br />```python<br />students = [("Alice", [85, 90, 75, 92]), ("Bob", [88, 92, 78, 85]), ("Charlie", [76, 82, 90, 78])]<br /><br />averages = calculateAverages(students)<br />print(averages)<br /># Output: [('Alice', 85.5), ('Bob', 85.25), ('Charlie', 82.5)]<br />```<br />In this example, we first define a list of tuples containing student names and their test scores. We then call the `calculateAverages()` function with this list as input and store the result in the `averages` variable. Finally, we print the list of tuples containing each student's name and their average test score.
Derecelendirmek için tıklayın: