Exercise 14.4 - Why does it print my output and then say that that output wasn't received?


#1

Do you think the hidden values in the exercise may be bugged?

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(scores):     #input list of grades to this
	total = 0
	for x in range(len(scores)):
		total += scores[x]
	print total
  
grades_sum(grades)

#2

Hi @speed_reader_steve,

In that exercise, what do the instructions ask the user to have the grades_sum function do after the sum of the scores has been computed?


#3

It just says return the sum

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(scores):     #input list of grades to this
	total = 0
	for x in range(len(scores)):
		total += scores[x-1]
	print total
  
grades_sum(grades)

The second output was different on the other code, but on this one it’s 350, which seems to be what they ask - however, they read it as 0 for some reason.


#4

Yes, exactly. However, you have the function do this instead …

	print total

#5

Ohhh… yeah, that’s a common mistake.


#6

After you make the correction, be sure to have the statement that calls the function print the result if you want to see it displayed. This would do it …

print(grades_sum(grades))