can t assign to function call python

1705 просмотра

1 ответ

21 Репутация автора

I am trying to create a very basic combat feature for a text based adventure game and my issue is that I am relieving an error regarding this line in particular.

The error in question is a Syntax error: can’t assign to function call error and I am stumped on what is causing the issue and how to fix it.

Any feedback at all would be greatly appreciated.

The function in where that error lies is shown below.

Ответы (1)

0 плюса

1 Репутация автора

With the instruction random.choice(gold_dropped) += gold, you add the value of variable «gold» to something that «doesn’t exist» (it must be an existing variable, you cannot assign something to the anonymous result of a function). That is why the python interpreter complains.

You simply need to use an intermediate variable (validity of the instruction below checked with python 3.5):

I have the following code:

Whenever I try and run this script, I get the following:

Any help or ideas would be greatly appreciated.

3 Answers 3

It is not clear (to me at least) what it is you’re trying to achieve, but perhaps it is as simple as this:

As you might have guessed, F(x) is a function call. You’re calling the function F , which does not actually exist, passing it the argument x , which does not actually exist either. You need to give your variables legal names, like f_of_x .

and discard the function() method

Not the answer you’re looking for? Browse other questions tagged python or ask your own question.

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2019.11.15.35459

This line in my program:

causes me to get this error:

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

4 Answers 4

Syntactically, this line makes no sense:

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:

You wrote the assignment backward: to assign a value (or an expression) to a variable you must have that variable at the left s >

You are assigning to a function call:

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:

Оцените статью