This line in my program:
invest(initial_amount,top_company(5,year,year+1)) = subsequent_amount
causes me to get this error:
SyntaxError: can't assign to function call
How do I fix this and make use of value of the function call?
The “SyntaxError: can't assign to literal” error occurs when you try to assign a value to a literal value such as a boolean, a string, a list, or a number. To solve this error, ensure your variable names are names rather than values.
In Python, we can assign a function to a variable. And using that variable we can call the function as many as times we want. Thereby, increasing code reusability. Simply assign a function to the desired variable but without () i.e. just with the name of the function.
The four steps to defining a function in Python are the following: Use the keyword def to declare the function and follow this up with the function name. Add parameters to the function: they should be within the parentheses of the function. End your line with a colon.
The Python SyntaxError occurs when the interpreter encounters invalid syntax in code. When Python code is executed, the interpreter parses it to convert it into bytecode. If the interpreter finds any invalid syntax during the parsing stage, a SyntaxError is thrown.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With