Not seeing your question? It may still have been asked before – try () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
Other FAQs
The following are links to additional questions that our community has asked about this exercise:
This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!
lesson:
Exam Statistics / 5. Computing the Average
Please see my programm-code:
grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] # was given
def grades_sum(scores):
result = 0
for i in scores:
result += i
return result
def grades_averange(grades_input):
factor1 = grades_sum(grades_input)
result = factor1 / float(len(grades_input))
return result
print(grades_averange(grades)) #call of fuction and call to print
Result in console right:
80.4230769231
Given Error:
grades_average seems to be missing!
Can someone give me a advice, what Im doing wrong?
Sometimes an intermediate variable provides clarity concerning the functioning of your algorithm, sometimes it just seems to be clutter. I think it’s less a matter of conciseness than of aesthetics.
If, for instance, you’re going to need to compute many averages, “concise” code might result from defining a function to compute the average (or using numpy, where it’s a built-in), then making use of it whenever needed.
Hi, I’ve been playing around with this ‘computing the average’ code. I’ve written out two ways - one is a lot longer than the other!
I can’t figure out why Example 1 won’t print the correct result though? It prints 3. Examples 2 prints the correct number, 4.5. (Apologies the indents don’t show up but I don’t think that’s the problem!..)
Thanks for your help!
Alex
Example 1:
grades = [5, 4]
def grades_sum(x):
total = 0
for num in x:
total += num
total = total / len(x)
return float(total)
print grades_sum(grades)
prints 3
Example 2:
grades = [5, 4]
def grades_sum(x):
total = 0
for num in x:
total += num
return float(total)
def grades_received(x):
return float(len(x))
def avg(a, b):
total = grades_sum(grades) / grades_received(grades)
return float(total)