6. Just Weight and See quick question


#1

I already figured out the answer, but I have a quick question on why a certain code doesn't work.

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return sum(homework * .1,quizzes * .3,tests * .6)

"Oops, try again. get_average(alice) raised the following error: sum expected at most 2 arguments, got 3" is the error I get from the code above. in that code, I use sum().

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return homework * .1 + quizzes * .3 + tests * .6

In this code I just add them and it works. Why can't I use sum()?
`


#2

@apashtriku3,
The sum() Method is a predefined function which expects a =list= as an argument
thus

homework=2
quizzes=3
tests=6
print sum([homework * .1,quizzes * .3,tests * .6])

might have worked.
Read some discussions
http://stackoverflow.com/questions/1747130/sum-and-division-example-python
http://stackoverflow.com/questions/18730299/python-sum-function-with-list-parameter


#3

It did work. Thanks!