# 3. Control Flow 3 - Ternary Operators

**URL:** <https://forum.codewithmosh.com/t/3-control-flow-3-ternary-operators/3475>\
**Category:** Python\
**Created:** [March 21, 2021, 2:21pm UTC](https://forum.codewithmosh.com/t/3-control-flow-3-ternary-operators/3475 "2021-03-21T14:21:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iljackb](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@iljackb](https://forum.codewithmosh.com/u/iljackb)\
**Post date:** [March 21, 2021, 2:21pm UTC](https://forum.codewithmosh.com/t/3-control-flow-3-ternary-operators/3475/1 "2021-03-21T14:21:12Z")

</div>

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:

 ![Screen Shot 2021-03-21 at 3.11.57 PM](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/7/7c2a92ac6b433063feaffadbf867098ac7b7a846.png)

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [March 21, 2021, 4:54pm UTC](https://forum.codewithmosh.com/t/3-control-flow-3-ternary-operators/3475/2 "2021-03-21T16:54:26Z")

</div>

> [@iljackb](#):
>
> My code is identical to Mosh’s

No, it isn’t. The correct syntax is

```python
message = "eligible" if age >= 18 else "not eligible"

```

---

<div class="post-metadata">

**Author:** ![iljackb](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@iljackb](https://forum.codewithmosh.com/u/iljackb)\
**Post date:** [March 21, 2021, 5:36pm UTC](https://forum.codewithmosh.com/t/3-control-flow-3-ternary-operators/3475/3 "2021-03-21T17:36:45Z")

</div>

Thanks my bad.

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