ERROR
File "strategy.py", line 33
elif current_price <= 0.97 * max((price for price in prices[:i])):
SyntaxError:invalid syntax
ERROR
File "strategy.py", line 33
elif current_price <= 0.97 * max((price for price in prices[:i])):
SyntaxError:invalid syntax
The error message you've encountered is a SyntaxError: invalid syntax
which typically indicates that there's something incorrect with the way your Python code is written, and it doesn't adhere to the rules of the Python language.
Looking at the snippet provided:
elif current_price <= 0.97 * max((price for price in prices[:i]))
The issue lies within how max()
function is being used in this context.
The max()
function requires an iterable object or a sequence (like a list, tuple etc.) to find the maximum value from. In your case, you are using it on a generator expression (price for price in prices[:i])
. Generators cannot be directly used with max()
, because they don't create their values until iterated over.
To solve this issue, convert the generator into either a list or tuple before applying max()
:
elif current_price <= 0.97 * max([price for price in prices[:i]])
Or use an iterator approach instead of using .max()
directly:
max_value = max((price for price in prices[:i]))
...
elif current_price <= 0.97 * max_value:
This way, max()
will evaluate the generator expression once and return the maximum value present within it, which can then be utilized further in your conditions.
Let me know if you need more assistance or have any other questions!