Ternary operator problem in tutorial

hello everyone,

I did the following exercise as in the tutorial but it gave an error.

age=22
message = “eligible” if age >= 18 else message = “not eligible”
print(message)

PS E:\python tut\Helloworld> & C:/Users/nzd.digital/AppData/Local/Programs/Python/Python311/python.exe “e:/python tut/Helloworld/app.py”
File “e:\python tut\Helloworld\app.py”, line 2
message = “eligible” if age >= 18 else message = “not eligible”
^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Maybe you meant ‘==’ or ‘:=’ instead of ‘=’?
PS E:\python tut\Helloworld>

where the problem is?

You’re trying to define the massage variable in the expression after ‘else’,
that’s why throws you an error.

Massage variable will take the result from the expression.
massage = “Eligible” if age >= 18 else “Not Eligible”

Thank you so much :+1: