Computing the Average 5/9


#1

Can someone please help me out with what is wrong with this code?
Why it keeps returning the error message; ‘grades_average([2, 4]) returned 80.42307692307692 instead of the expected: 3.0’

and how it is any different from this code;

def grades_average(grades):
sums = grades_sum(grades)
G_average = sums / float(len(grades))
return G_average
print grades_average(grades)

Thanks in advance


#2

line 14:

grades_input = grades

why would you overwrite your function parameter? Given your function a parmeter and then overwriting the parameter defeats the point of parameters, and renders the argument you supply at function call (as shown in the error message) completely useless.

Functions should be flexible, being able to handle multiple different list (which is why we use parameters and arguments), not handling a single list (grades in your code)


#3
  1. This was my original code following the instructions. It was because it kept returning the error message that I modified it.

  1. The instructions clearly stated that the function should carry one argument “grades_input” but the 2nd code shows “grades” instead. This is equally reflected in formula for grades_average. Giving “G_average = sums / float(len(grades))” instead of “grades_average = grades_sum(grades_input / float(lengrades_input))”.

I really dont understand why these terms should be different from the ones given in the instructions and the editor return an error message even though I was following the instructions.


#4

this would simple mean the instructions and get code are not in sync, seems there are a few exercises where this is a problem.

but they are just variable names, its more important to understand how the function works


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.