How to write a program in python in which when the numerical input is taken then the result is the sum of all the individual digit in the input
For ex - Input=357 result =3+5+7=15
Answers
Answered by
4
Solution 1:
print(sum(int(x) for x in str(int(input("Number: "))).replace("", " ").split()))
Solution 2:
number = str(int(input("Number: "))).replace("", " ").split() # splitting digits
sum_ = 0
for i in number:
sum_ += int(i)
print(sum_)
Similar questions
English,
4 hours ago
Social Sciences,
4 hours ago
Physics,
4 hours ago
History,
7 hours ago
Math,
7 hours ago
Science,
8 months ago
Math,
8 months ago
Social Sciences,
8 months ago