# Умова IF

#### **Перевірка, чи змінна не порожня**

{% hint style="info" %}
Щоб переконатися, що змінна містить значення (тобто вона не `None` і не є порожнім рядком), потрібно перевірити, що вона **НЕ дорівнює** порожньому рядку.

**Правильна формула:**

`"#{value}" != ""`

Це важливо для перевірки даних, наприклад, щоб переконатися, що відповідь була отримана від зовнішнього API-запиту, перш ніж продовжувати.
{% endhint %}

### IF()

<details>

<summary>Опис</summary>

**if(condition, value\_if\_true, value\_if\_false)**

**condition** - trigger

**value\_if\_true** - value if True

**value\_if\_false** - value if False

{% hint style="warning" %}
Максимальна довжина виразу: 2000 символів
{% endhint %}

</details>

<details>

<summary>Приклад</summary>

Розгляньмо кілька прикладів:

SILENCEDAYS\_2 = if(SILENCEDAYS\_2 == 1, 1, 0). У цьому випадку, якщо змінна `SILENCEDAYS_2` існує та дорівнює 1, її значення залишається 1. Якщо вона не існує або має інше значення, їй буде присвоєно 0. Це корисно перед виконанням математичних операцій, щоб захиститися від порожніх або невизначених значень змінних.

ClientName = if(ClientName == 1, P1, if(ClientName == 2, P2, if(ClientName == 3, P3, 7))), де P1, P2, P3 — це змінні.&#x20;

Якщо ClientName дорівнює 1, тоді буде присвоєно значення P1;\
якщо ClientName дорівнює 2, тоді буде присвоєно значення P2;\
якщо ClientName дорівнює 3, тоді буде присвоєно значення P3;\
інакше буде присвоєно значення 7.

Як бачите, можна використовувати вкладені конструкції if. Це корисно, коли ви хочете навчити бота обчислювати суму замовлення, де ціна за одиницю залежить від кількості:

Order\_Amount = round(if(Quantity >=100, if(Quantity >=200, if(Quantity >=300, if(Quantity >=400, if(Quantity >=500, if(Quantity >=1000, if(Quantity >=2000, if(Quantity >=3000, if(Quantity >=5000, 25\*Quantit&#x79;*, 30\**&#x51;uantity), 35\*Quantit&#x79;*), 40\**&#x51;uantity), 45\*Quantit&#x79;*), 50\**&#x51;uantity), 55\*Quantit&#x79;*), 60\**&#x51;uantity), 65\*Quantit&#x79;*), "Не вдається обчислити... Десь у вашому замовленні сталася помилка. Будь ласка, почніть спочатку ще раз.")* \* 100) / 100

<div data-with-frame="true"><figure><img src="/files/3391de759ac0c7bcae0477279bc0731d84ee5e20" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/47a734493edc1d3a021ac2c397781a721d328ba0" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/b3cc65a435cb52e879d58d27deaf5773e351581d" alt=""><figcaption></figcaption></figure></div>

</details>

<details>

<summary>Приклад коду для копіювання</summary>

<pre><code>SILENCEDAYS_2 = if(SILENCE_DAYS_2 == 1, 1, 0)
ClientName = if(ClientName == 1, Р1, if(ClientName == 2, Р2, if(ClientName == 3, Р3, 7)))
<strong>Order_Amount = round(if(Quantity >=100, if(Quantity >=200, if(Quantity >=300, if(Quantity >=400, if(Quantity >=500, if(Quantity >=1000, if(Quantity >=2000, if(Quantity >=3000, if(Quantity >=5000, 25*Quantity, 30*Quantity), 35*Quantity), 40*Quantity), 45*Quantity), 50*Количество), 55*Quantity), 60*Quantity), 65*Quantity), "Не вдається обчислити... Десь у вашому замовленні сталася помилка. Будь ласка, почніть спочатку ще раз.")  * 100) / 100
</strong></code></pre>

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/doc/uk/chatbot/functions/kalkulyator/conditional.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
