interactive-coding-challenges icon indicating copy to clipboard operation
interactive-coding-challenges copied to clipboard

sum_two sample solution parameter

Open MarkMoretto opened this issue 4 years ago • 2 comments

For the sum_two_challenge notebook (link), the Solution class template only takes one parameter:

class Solution(object):

    def sum_two(self, val):
        # TODO: Implement me
        pass

That should change to two parameters:

class Solution(object):

    def sum_two(self, a, b):
        # TODO: Implement me
        pass

Otherwise a TypeError is raised with the message:

TypeError: sum_two() takes 2 positional arguments but 3 were given

MarkMoretto avatar Jun 26 '21 20:06 MarkMoretto

Hey Mark, We can still solve this by using the variable argument syntax in the sum_two method

class Solution(object): def sum_two(self, *val): return sum(val)

Run the test cases and it will pass all of them. Appreciate any feedback from your side.

suhasthegame avatar Aug 25 '21 07:08 suhasthegame

For the sum_two_challenge notebook (link), the Solution class template only takes one parameter:

class Solution(object):

    def sum_two(self, val):
        # TODO: Implement me
        pass

That should change to two parameters:

class Solution(object):

    def sum_two(self, a, b):
        # TODO: Implement me
        pass

Otherwise a TypeError is raised with the message:

TypeError: sum_two() takes 2 positional arguments but 3 were given

def sum_two(self, *val): return val

you can enter multiple values when we use (*args) and (**kwargs) takes keywords arguments

harsh1509c avatar Oct 05 '23 14:10 harsh1509c