Определить, сколько в числе четных цифр, а сколько нечетных. Число вводится с клавиатуры.
Python
# Считываем число
number = int(input("Введите число: "))
# Инициализируем счетчики четных и нечетных цифр
even_count = odd_count = 0
# Обрабатываем каждую цифру числа
while number > 0:
digit = number % 10
if digit % 2 == 0:
even_count += 1
else:
odd_count += 1
number //= 10
# Выводим результат
print("Количество четных цифр:", even_count)
print("Количество нечетных цифр:", odd_count)
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.