'Error in Python: missing 1 required positional argument
I'm not so good with python and I keep getting this error:
TypeError: demand_curve() missing 1 required positional argument: 'pb'
And this is my code:
P,c,Q,y,pb,N,X,pf,t=sp.symbols('P c Q y pb N X pf t')
def demand_curve(c,Q,y,pb):
demand = (c.log(Q)-(-4.507+(0.841*y)+(0.2775*pb)))/(-0.397)
return demand
Q_num = np.linspace(0,100,100)
fig,ax=plt.subplots()
ax.set_ylabel('P')
ax.set_xlabel('E')
ax.plot(demand_curve(Q_num, 50, 2), Q_num,label='E (a=100,b=2)')
#legend:
ax.legend(loc='upper right', frameon=False)
ax.set(xlim=(0,100))
ax.set(ylim=(0,60))
I don't really understand what is the problem, can someone help me?
Solution 1:[1]
When you declare your function you do this :
def demand_curve(c,Q,y,pb):
...
So you have four parameters c, Q, y and pb, later in the code you call it using :
demand_curve(Q_num, 50, 2)
So in the way you call it you have
- c = Q_num
- Q = 50
- y = 2
- pb = Nothing at all
And python don't like this so you should provide and additional value when you call this function or provide a default value for the last parameter for example :
def demand_curve(c,Q,y,pb = "a default value"):
...
Solution 2:[2]
You are not passing all the arguments value when you call you function "demand_curve". Your function "demand_curve(c,Q,y,pb)" required 4 positional arguments but you give only 3 at "demand_curve(Q_num, 50, 2)".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xiidref |
| Solution 2 | Yash Talaiche |
