The overall structure you're looking for, since you are trying to accomplish an assignment with multiple conditional expressions, is this:
variable = expression condition else expression condition ... else expression. You can even use parentheses to remind yourself of how it will be parsed: variable = (expression condition else expression condition ... else expression). The total conditional expression must end with "else".
For instance, I have the following code:
x = 5
if x == 1:
a = '1'
elif x == 2:
a = '2'
else:
a = '3'
print(a)
Using a conditional expression, it becomes:
x = 5
a = '1' if x == 1 else '2' if x == 2 else '3'
print(a)
I'm not sure what your assignment and conditional expressions
if i+1 < stages[i]: tried[i] = (tried[i] + 1) if tried[i] != None else tried[i] = 0
would look like when expanded, as some information is missing:
missing_expression = '?'
if i+1 < stages[i]:
tried[i] = (tried[i] + 1)
elif tried[i] != None:
tried[i] = missing_expression
else:
tried[i] = 0
When the missing expression is supplied, your conditional expression should look like:
tried[i] = (tried[i] + 1) if i+1 < stages[i] else missing_expression if tried[i] != None else 0
if elsestatement instead?true_expr if cond else false_expronly works with expressions. Assignment is not an expression; use the fullifstatement, or extract the assignment outside theifexpression.0as in the answers below, it would work. Nevertheless, a line break after the firstifstatement would, e.g., help. The readability of mixingifand conditional is definitively not the best.