25

This line:

invest(initial_amount,top_company(5,year,year+1)) = subsequent_amount

produces an error:

SyntaxError: can't assign to function call

How do I fix this and make use of value of the function call?

Mateen Ulhaq
  • 21,459
  • 16
  • 82
  • 123
Richee Chan
  • 243
  • 1
  • 4
  • 5

3 Answers3

22

Syntactically, this line makes no sense:

invest(initial_amount,top_company(5,year,year+1)) = subsequent_amount

You are attempting to assign a value to a function call, as the error says. What are you trying to accomplish? If you're trying set subsequent_amount to the value of the function call, switch the order:

subsequent_amount = invest(initial_amount,top_company(5,year,year+1))
Brian Clapper
  • 24,425
  • 7
  • 63
  • 65
8

You wrote the assignment backward: to assign a value (or an expression) to a variable you must have that variable at the left side of the assignment operator ( = in python )

subsequent_amount = invest(initial_amount,top_company(5,year,year+1))
Riccardo Galli
  • 11,485
  • 5
  • 64
  • 60
1

You are assigning to a function call:

invest(initial_amount,top_company(5,year,year+1)) = subsequent_amount

which is illegal in Python. The question is, what do you want to do? What does invest() do? I suppose it returns a value, namely what you're trying to use as subsequent_amount, right?

If so, then something like this should work:

amount = invest(amount,top_company(5,year,year+1),year)
Mark Amery
  • 127,031
  • 74
  • 384
  • 431
Tim Pietzcker
  • 313,408
  • 56
  • 485
  • 544
  • Then you must have a literal like a number or a string (in quotes) on the left-hand side of the assignment. – Tim Pietzcker Mar 24 '19 at 13:56
  • then I can not put the value neither on the left nor on the right ! that will be an infinite cycle !! – FabioSpaghetti Mar 24 '19 at 14:32
  • The name (variable) goes on the left, the value on the right. This is the same across practically all programming languages. – Tim Pietzcker Mar 24 '19 at 14:48
  • yes !! doing that , I get : “can't assign to function call” – FabioSpaghetti Mar 24 '19 at 15:04
  • You must be having a function call on the left side (something like `foo(bar, baz) = 123`. There may only be names, possibly tuples, on the left side. Please show the line that‘s causing the error. – Tim Pietzcker Mar 24 '19 at 15:08
  • Thank you very much, I add those lines but you might not know the module, it's to run a software called femap from python: import Pyfemap app = Pyfemap.model(existObj) app = Pyfemap.model(existObj) feProp = app.feProp feProp.pval(7)= 10 this is not possible cause feProp.pval(7) is already a value – FabioSpaghetti Mar 24 '19 at 22:23
  • I think you should ask a new question for this with an explanation of what that code is supposed to be doing. If you have any links to the Pyfemap documentation, those would be handy, too. One stab in the dark: If `feProp.pval` is a list, then `feProp.pval[7] = 10` might work. Note the square brackets. – Tim Pietzcker Mar 25 '19 at 08:31
  • just in case, Stack has banned me from posting new questions I don't know how to ask now !! – FabioSpaghetti Mar 25 '19 at 08:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/190605/discussion-between-tim-pietzcker-and-fabiospaghetti). – Tim Pietzcker Mar 25 '19 at 08:51