0

This is the code

def summationTwo(lower, upper, margin):
    """Returns the sum of the numbers from lower through upper, 
    and outputs a trace of the arguments and returns values on
    each call"""
    blanks = " " * margin
    print(blanks, lower, upper)
    if lower > upper:
        print(blanks, 0)
        return 0
    else:
        result = lower + summation(lower + 1, upper, margin + 4)
        print(blanks, result)
        return result
summationTwo (1, 4)

When I plug in two arguments for the summationTwo function call, I get a traceback that says, "TypeError: summation() takes 2 positional arguments but 3 were given."

However, when I plug in but two arguments, I get this traceback: "TypeError: summationTwo() missing 1 required positional argument: 'margin'"

What's going on?

3
  • 1
    summation isn't the same function as summationTwo. When you call with only two arguments then you haven't provided enough arguments. That's an error and things stop right there. When you supply three arguments then it gets through that and actually calls the function. When it gets to the line calling summation with too many arguments then that's the error. I don't know this summation function and I don't see it defined here so I don't really know what arguments it expects. But the error message seems to imply that it only takes two. Commented Sep 22, 2020 at 2:15
  • Ugh, I am so blind sometimes! Thank you! Commented Sep 22, 2020 at 2:23
  • I’ll make it an answer. Please accept it. Commented Sep 22, 2020 at 2:32

1 Answer 1

1

summation isn't the same function as summationTwo. When you call with only two arguments then you haven't provided enough arguments. That's an error and things stop right there. When you supply three arguments then it gets through that and actually calls the function. When it gets to the line calling summation with too many arguments then that's the error. I don't know this summation function and I don't see it defined here so I don't really know what arguments it expects. But the error message seems to imply that it only takes two

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.