
С клавиатуры вводится шестизначное число, определить является ли оно счастливым. Т.е. сумма первых
трех цифр равна сумме второй тройки цифр. Если да - вывести `1`, если нет - `0`. (Воспользоваться тем, что `0` делится на любое число).

Ответы на вопрос

реализация в python
a = list(map(int, list(input())))
if len(a) == 6:
if sum(a[:3]) == sum(a[3:]):
print(1)
else:
print(0)
else:
print("ERROR: length of number != 6")



Problem Statement
You are given a six-digit number entered from the keyboard. You need to determine whether it is a "happy" number. A number is considered "happy" if the sum of the first three digits is equal to the sum of the last three digits. If it is a "happy" number, output `1`; otherwise, output `0`. You can use the fact that `0` is divisible by any number.Solution
To determine whether a six-digit number is "happy," we need to calculate the sum of the first three digits and the sum of the last three digits. If these two sums are equal, the number is "happy" and we output `1`; otherwise, we output `0`.Here's the algorithm to solve this problem: 1. Read the six-digit number from the keyboard. 2. Extract the first three digits and the last three digits from the number. 3. Calculate the sum of the first three digits and the sum of the last three digits. 4. If the sums are equal, output `1`; otherwise, output `0`.
Let's implement this algorithm in Python:
```python number = int(input("Enter a six-digit number: "))
# Extract the first three digits and the last three digits first_three_digits = number // 1000 last_three_digits = number % 1000
# Calculate the sum of the first three digits and the sum of the last three digits sum_first_three_digits = first_three_digits // 100 + (first_three_digits // 10) % 10 + first_three_digits % 10 sum_last_three_digits = last_three_digits // 100 + (last_three_digits // 10) % 10 + last_three_digits % 10
# Check if the sums are equal and output the result if sum_first_three_digits == sum_last_three_digits: print(1) else: print(0) ```
Please note that this solution assumes the input is a valid six-digit number. You may need to add additional input validation if necessary.
Example:
Input: ``` Enter a six-digit number: 123321 ``` Output: ``` 1 ```
Explanation:
In this example, the first three digits are 123, and the last three digits are 321. The sum of the first three digits is 1 + 2 + 3 = 6, and the sum of the last three digits is 3 + 2 + 1 = 6. Since the sums are equal, the number is "happy," and the output is `1`.


Похожие вопросы
Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili