Computer Science, asked by LostInSongYT, 7 hours ago

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 atrs7391
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