 Can you copy the relevant piece of code and the full traceback and paste

Posting an image makes it difficult or impossible for some people,
either due to technical limitations, or because they are blind or

Thank you.

1 Like

import numpy as np
class Solution():
def findMedianSortedArrays(n1,n2):
a=0
n1=np.array(n1)
n2=np.array(n2)
sum1=0
n3=n1+n2
for i in n3:
sum1=sum1+i
a=a+1
return (sum1/a)

function call
sum1=Solution().findMedianSortedArrays(1,2)

## trace

TypeError Traceback (most recent call last)
in
----> 1 sum1=Solution().findMedianSortedArrays(1,2)

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

sorry thanks for pointing out

Thanks for posting the code.

You have forgotten the “self” parameter for the instance.

You have:

``````class Solution():
def findMedianSortedArrays(n1,n2):
...
``````

so when you call this as a method later on:

``````sum1=Solution().findMedianSortedArrays(1,2)
``````

Python tries to give the “findMedianSortedArrays” function three
arguments, the instance (self) plus the two values you provide (1 and 2)
but the function only accepts two arguments, n1 and n2. So you need to
give it a third:

``````    def findMedianSortedArrays(self, n1, n2):
``````

Unfortunately this is one place where the error messages are a bit
tricky to interpret:

``````findMedianSortedArrays() takes 2 positional arguments but 3 were given
``````

unless you have a fair amount of experience with Python. The error
message is technically correct, but hard for beginners to understand.

Any time you get an error like this, check that you haven’t forgotten
the self parameter of your methods.