3. Control Flow 3 - Ternary Operators

My code is identical to Mosh’s see below however I get an error (see screenshot):

age = 22
message = "Eligible" if age >= 18 else message = "Not Eligible"
print(message)

I get the following error:

SyntaxError: can't assign to conditional expression

In the “Problems window”, the error message is as follows:
cannot assign to conditional expression (<unknown>, line 59)

I’m using Python 3.8.5 in case that matters. Since there are other ways of doing this code it’s not the worst thing but it’s annoying not to be able to follow along at such an early juncture.

Here is my code and the result window:

No, it isn’t. The correct syntax is

message = "eligible" if age >= 18 else "not eligible"
1 Like

Thanks my bad.

I would delete the issue but it doesn’t seem possible…