SyntaxError: "cannot assign function call"

This line in my program:

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

makes me get this error:

SyntaxError: can't assign to function call

How to fix this and use function call value?

+5
source share
3 answers

Syntactically this line does not make sense:

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

You are trying to assign a value to a function call, as the error says. What are you trying to achieve? If you are trying to set a value subsequent_amountto a function call value, reorder:

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

You wrote the assignment back: to assign a variable (or expression) to a variable you must have this variable on the left side of the assignment operator (= in python)

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

:

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 it do invest()? I suppose it returns a value, namely what you are trying to use like subsequent_amount, right?

If so, something like this should work:

amount = invest(amount,top_company(5,year,year+1),year)
0
source

All Articles