Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Foundations of Programming Python Exam - Topic 4 Question 9 Discussion

SIMULATIONWrite 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 floatpass
A) See the Step by Step Solution below in Explanation

WGU Foundations of Programming Python Exam - Topic 4 Question 9 Discussion

Actual exam question for WGU's Foundations of Programming Python exam
Question #: 9
Topic #: 4
[All Foundations of Programming Python Questions]

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

Show Suggested Answer Hide Answer
Suggested Answer: A

==========

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


Contribute your Thoughts:

0/2000 characters
Sylvia
7 hours ago
I feel like I should use the built-in sum function, but what if I forget how to calculate the length of the list?
upvoted 0 times
...
Marcos
5 days ago
This seems similar to that practice question about calculating the mean. I hope I can remember the exact syntax!
upvoted 0 times
...
Sabina
11 days ago
I'm not entirely sure how to handle an empty list. Do we just return 0.0 or something else?
upvoted 0 times
...
Whitney
16 days ago
I think I remember we need to sum the grades and then divide by the number of grades, right?
upvoted 0 times
...

Save Cancel