Get the sum of digits in Python
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 4 )
sum=0
while (Input>0):
sum=sum+Input%10
Input=Input//10
print(sum)
Def getSum(n):
Sum=0
For digit in str(n):
Sum+= int(digit)
Return sum
def summ(x):
x = str(x)
Sum=0
for i in x:
Sum = Sum + int(x)
return Sum
print(“sum of digits: “, summ(342))
num=342
sum=0
num=[int(i) for i in str(num)]
for i in num:
sum=sum+i
print(sum)