Many conditions

Many conditions - Сообщения

#1 Опубликовано: 17.08.2021 04:30:44
Vasia

Vasia

0 сообщений из 17 понравились пользователям.

Группа: User

Здравствуйте.
Столкнулся со следующей проблемой: есть несколько условий, необходимо, чтобы при заданных значениях правильно бралось значение "а".
У меня почему-то игнорируется последнее условие - p0, то есть, в моем случае должно быть а=4, а программа выдает а=3.
Что я сделал не так?
example.jpg
proba.sm (11 КиБ) скачан 23 раз(а).
#2 Опубликовано: 17.08.2021 04:47:43
sergio

sergio

115 сообщений из 329 понравились пользователям.

Группа: User

I don't see error in Smath as the reports indicated in the third "If" are all verified and therefore does not even pass to the fourth "IF". Maybe you should add that P0 = 0 (or something else).
P.S. I also point out an OR in the fourth "IF" while all the others are AND: it could be an oversight
sergio
#3 Опубликовано: 17.08.2021 04:54:56
Vasia

Vasia

0 сообщений из 17 понравились пользователям.

Группа: User

Wrote

I don't see error in Smath as the reports indicated in the third "If" are all verified and therefore does not even pass to the fourth "IF". Maybe you should add that P0 = 0 (or something else).
P.S. I also point out an OR in the fourth "IF" while all the others are AND: it could be an oversight
sergio



Спасибо, понял, что надо сделать - в первые три варианта прописал p0<100 и все заработало.
#4 Опубликовано: 17.08.2021 11:30:24
overlord

overlord

552 сообщений из 1332 понравились пользователям.

Группа: Moderator

Wrote

Спасибо, понял, что надо сделать - в первые три варианта прописал p0<100 и все заработало.


You don't have to describe p<100. Just re-order the if statements.
In original, third statement if condition gets true regardless of p.0 value.
When it gets the true value in if condition, it won't be looked for next if.
Moving the p.0 boolean check to first will make all conditions available to read.

You can use cases() for smaller, tidier and much readable if blocks.
Using nested if() and cases() will reduce the huge block of boolean.
Your φ.n - λ.n - h.q checks are same for all, nesting λ under it is possible.
And you can also use multiple boolean conditions. lele(),lelt(),gege(), etc.

Regards

proba_r1.sm (5 КиБ) скачан 26 раз(а).

2021-08-17_17-29.png
#5 Опубликовано: 18.08.2021 10:56:50
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Maths lele.sm (8 КиБ) скачан 24 раз(а).
#6 Опубликовано: 18.08.2021 11:44:26
overlord

overlord

552 сообщений из 1332 понравились пользователям.

Группа: Moderator

You can even triple nest boolean checks.
0.5<=λ<=0.6 can be written as one cases().

Regards

2021-08-18_17-42.png
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений