SIMULATION
Write a complete function calculate_average(grades) that takes a list of grades and returns the average as a float.
For example, calculate_average([85, 92, 78]) should return 85.0.
def calculate_average(grades):
# TODO: Calculate and return the average grade as a float
pass
==========
Step 1: The function receives one parameter named grades, which is a list of numbers.
Step 2: Use sum(grades) to add all the grades together.
Step 3: Use len(grades) to count how many grades are in the list.
Step 4: Divide the total by the number of grades.
Correct code:
def calculate_average(grades):
return sum(grades) / len(grades)
Example:
print(calculate_average([85, 92, 78]))
Output:
85.0
Sylvia
7 hours agoMarcos
5 days agoSabina
11 days agoWhitney
16 days ago