I tried writing
age = 22
message = "Eligible" if age>=22 else message = "not eligible"
print(message)
The above code is failing with the error
SyntaxError: cannot assign to conditional expression
Why doesn't this work?
I tried writing
age = 22
message = "Eligible" if age>=22 else message = "not eligible"
print(message)
The above code is failing with the error
SyntaxError: cannot assign to conditional expression
Why doesn't this work?
You only need to get rid off the message =
after the else statement.
message = "Eligible" if age>=22 else "not eligible"
Ternary operators are structed like:
variable = [value on_true] if [expression] else [value on_false]