Files
operators/operators_30.py
2025-12-11 18:06:09 +05:00

49 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
input_str = input("Введите целые числа через пробел: ")
numbers = [int(x) for x in input_str.split()]
print(f"Список: {numbers}")
print()
all_positive_loop = True
for num in numbers:
if num <= 0:
all_positive_loop = False
break
print(f"Все элементы положительные (цикл): {all_positive_loop}")
all_positive_func = all(num > 0 for num in numbers)
print(f"Все элементы положительные (all): {all_positive_func}")
print()
has_zero_loop = False
for num in numbers:
if num == 0:
has_zero_loop = True
break
print(f"Есть нулевой элемент (цикл): {has_zero_loop}")
has_zero_func = any(num == 0 for num in numbers)
print(f"Есть нулевой элемент (any): {has_zero_func}")
print()
all_even_loop = True
for num in numbers:
if num % 2 != 0:
all_even_loop = False
break
print(f"Все элементы четные (цикл): {all_even_loop}")
all_even_func = all(num % 2 == 0 for num in numbers)
print(f"Все элементы четные (all): {all_even_func}")
print()
has_odd_loop = False
for num in numbers:
if num % 2 != 0:
has_odd_loop = True
break
print(f"Есть нечетный элемент (цикл): {has_odd_loop}")
has_odd_func = any(num % 2 != 0 for num in numbers)
print(f"Есть нечетный элемент (any): {has_odd_func}")