returning totals in functions of math
Ok, I don't know how to change add to accept an arbitrary number of
arguments (I'm pretty new) and as for total = 1 idk but it worked for other
versions of this (multiplication), and figured it might work for this one,
do you have any tips on what a better number might be for the total to
On Sun, 8 Nov 2020 at 14:37, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
> On 2020-11-08 at 19:00:34 +0000,
> Peter Pearson <pkpearson at nowhere.invalid> wrote:
> > On Sun, 8 Nov 2020 13:50:19 -0500, Quentin Bock <qberz2005 at gmail.com>
> > > Errors say that add takes 1 positional argument but 3 were given? Does
> > > limit how many numbers I can have or do I need other variables?
> > > Here is what I have:
> > > def add(numbers):
> > > total = 1
> > > for x in numbers:
> > > total += x
> > > return total
> > > print(add(1999, -672, 84))
> > Your function "add" expects a single argument that is a list
> > of numbers. You're passing it three arguments, each a number.
> > Try add([1999, -672, 84]).
> Or change add to accept an arbitrary number of arguments and collect
> them into a tuple:
> def add(*numbers):
> # then the rest of the function as before
> BTW, why initialize total to 1?