0

I was reading 'Starting Python' trying out in the shell some of the examples.
However, I get an error with this one. What am I doing wrong?

>>> def sum_average(*args):
    size = len(args)
    sum1 = sum(args)
    average = sum1/float(size)
    # return a tuple of three arguments
    # args is the tuple we passed to the function
    return args, sum1, average

>>> sum_average(1, 2, 3, 4, 5)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    sum_average(1, 2, 3, 4, 5)
  File "<pyshell#2>", line 3, in sum_average
    sum1 = sum(args)
  File "<pyshell#14>", line 3, in sum
    sum1 = sum(numbers)
    [...]
  File "<pyshell#14>", line 3, in sum
    sum1 = sum(numbers)
  File "<pyshell#14>", line 3, in sum
    sum1 = sum(numbers)
RuntimeError: maximum recursion depth exceeded

Thanks.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by woooee
0

Te following works fine for me. What version of Python are you using?

def sum_average(*args):
    size = len(args)
    sum1 = sum(args)
    average = sum1/float(size)
    # return a tuple of three arguments
    # args is the tuple we passed to the function
    return args, sum1, average

print sum_average(1, 2, 3, 4, 5)

## prints ((1, 2, 3, 4, 5), 15, 3.0)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.