+ 2
Any() or all()
Iteration over the array with the definition of the parity of the number. The attachment is a simple option. How can I do this using any () or all () functions ? --- Перебор массива с определением четности числа. Во вложении простой вариант. Как это сделать с помощью функций any() или all()? https://code.sololearn.com/cq57LFb3AEwp/?ref=app
11 Respuestas
+ 6
here is a code snippet that you can use to see how it works. Input is given as space separated numbers. They will be split and converted to int and then stored in a list. This is the base for any() or all().
inp = [int(i) for i in input('enter some numbers sep. by space: ').split()]
if all(j % 2 == 0 for j in inp):
print('all numbers are Even')
else:
print('not all numbers are Even')
+ 7
print("NO" if any(filter(lambda k:k%2, b)) else "YES")
+ 5
print("even" if any(i%2 for i in [2,4,6,8,0,2,4,8,0]) else "odd")
+ 2
Your code doesn't use an array (or list), the loop is running in range. Did you attach the right code link?
+ 2
Ok, just FYI, all() or any() needs an iterable object to work with. I don't understand why would you need either one of those functions to check for even or odd number.
+ 2
Try this I think this is what you want.
print("NO" if any([n % 2 for n in b]) else "YES")
An example is also available in the Python tutorial
https://www.sololearn.com/learn/Python/2456/
+ 2
Ipang thanks!
+ 1
Ipang
Ok. It was a code where are you input 10 numbers:)))) and after i look all numbers aret even or not
+ 1
Ipang i want without "for"
Maybe print("yes" if any(b[i]%2) else "no")
0
No sweat buddy 👌