I'm trying to simplify a chain comparison from 3 lines:
if -10 < amount < 10: # amount can range from -999 to 999
width = 3
else:
width = 2
to a 1 line expression:
width = 3 if (-10 < amount < 10) else width = 2
Pycharm throws a SyntaxError
SyntaxError: can't assign to conditional expression
What would be to correct way to write simplify this statement? I tried:
width = 3 if (-10 < amount) else width = 2
but I receive the same error. I'm using Python 3. Thanks.