Answer the question
In order to leave comments, you need to log in
Find the sum of the digits of a four-digit number, help?
Given a four-digit number. Find the sum of its digits.
Examples
Input
Output
2020
4
An example of finding a three-digit number:
x = int(input())
x1 = x//100
x2 = (x//10)%10
x3 = x%10
Do the same for this example, operators at a higher site level does not accept
Answer the question
In order to leave comments, you need to log in
print(sum(map(int, list(input()))))
For any number of digits in a number
number = str(input('Введите число: '))
sum_ = 0
for char in number:
sum_+= int(char)
print(sum_)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question