Question
How can I calculate a weighted average?
Answer
This part is a bit tricky, but basically we’re adding up parts to make a whole. That is, after all, the point of weighting these averages.
So if we say homework is 10%, quizzes are 30%, and tests are 60%, that accounts for 100% of the pie. When we go to return our value, then, we just multiply each average that we’ve calculated by its respective weight in decimal form, like this:
return (part_1 * part_1_weight) + (part_2 * part_2_weight) + (part_3 * part_3_weight)