S
S
Soul12020-09-01 15:50:37
Python
Soul1, 2020-09-01 15:50:37

How to shorten a condition in Python?

Just started to learn programming, so sorry for the noob question. I honestly googled and couldn't find it. Tell me how to make a short record for enumeration in a condition in Python.
Let's say we have a code:

x = 1
while x % 2 !=0 or x % 3 !=0 or x % 4 !=0:
    x += 1

How to make a short note? Something like while x % 2, 3, 4 != 0 ? It is through enumeration. And the second question - how to implement the same thing through the list? Let's say before that we created a list a = (1, 5).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-09-01
@Soul1

a = (2, 3, 4)
while any(x % i != 0 for i in a):
    x += 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question