The problem is that this single Python code has several naming problems. And the problem you are showing:
Quote:
When I use this code it keeps saying that acc is not defined
... is likely not to be raised from this piece of code. If it is, then just change the
acc
to
account
; since you have passed and created an "
account
" variable (again!)
Secondly, there are several other problems with the code. You can see, in the first line under decision == True: you have:
if (balance>= fprice):
But you never defined
fprice
variable anywhere. On and on with so many other variables, like
stock_quant
,
quant
, etc.
Although Python is flexible with the naming, dynamic (or duck) typing, you at least need to provide the information to the interpreter to "know" that a variable was intended. Once you will create the variables, initialize with anything (since Python is not forcing a type) your "defined / undefined" problems will go away. This will introduce other problems like a type mismatch, but that can be easily tackled.
Please see these links to learn more on this:
typing — Support for type hints — Python 3.8.2 documentation[
^]
python - input() error - NameError: name '...' is not defined - Stack Overflow[
^] (
Note that this answer discusses a case where your input values are shown as not defined in the Python code,
read this if your "acc
" comes from your input)