How to use common condition

ex, string type variable 3
a1 = “12345678”
a2 = “11112222”
a3 = “77775555”

if(a1.count = 8 and a2.count = 8 and a3.count =8 ) << “problem”
start ~~
즉, 3개의 변수 모두가 8자리를 나타낼 때 어떤 행동을 취한다라고 할때
if문 내에 조건을 깔끔하게 다시 정리할 수 있는 방법이 있을까요? (코드를 줄이는것이 목적)
(a1 and a2 and a3).count = 8 << 이런식으로 줄이려고 하는데 이렇게 하니까 안되네요.
i want “problem” change neat


you probably want to use a1.length with a string variable, the if should work then.

Best Regards

The ‘if’ works well, too
I want a more concise sentence.

because If there are more variables, the inside of the if statement you are using now becomes too long.

Do you have a different number of variables for each run?

If you just want to shorten it e.g. for 3 variables (and they are strings) you also could do something like: (a1 + a2 + a3).length = 24 → Problem

Best Regards

thank you
you genius

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.