Sum() function


#1
  1. Just weight and see

my code for this exercise was returning an error message because in the las line I was using sum() instead of just writing
return ('homework' * 10) + ('quizzes'30) + ('tests'60)

I'm wondering what the difference is.
Thank you!

`


#2

Both sum and the + operator can be used to calculate the sum of two integers, perhaps you just weren't using both methods correctly, if so you would need to find out how to use each one and compare to what you did. Functions expect some particular input, if you gave it something else then there's no wonder it wasn't doing what you wanted. For any function that you ever use, you will need to produce input that it knows what to do with, finding out what that is is a matter of reading its documentation. In the case of sum and other functions that are always present without importing anything, you can find it by googling "python built-in functions", look for results on python.org and choose either python 2 or python 3 depending on which interpreter you are using


#3

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