-
Notifications
You must be signed in to change notification settings - Fork 244
Average Score
Sar Champagne Bielert edited this page Apr 8, 2024
·
5 revisions
Unit 1 Session 2 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Should my function return an integer?
- Not necessarily. Some averages might happen to be integers, but you should not be rounding the results in any way.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Calculate the average of a list of integer scores.
0) Remember that average can be calculated using (sum of values / number of values)
1) Create a variable to store the sum
2) Loop through the list, and add each value to the sum variable
3) Divide the sum variable by the length of the list and return the result
def average(scores):
total = 0
for score in scores:
total += scores
return total / len(scores)