plus2net.com offers FREE online classes on Basics of Python for selected few visitors.

Read more on course content , Details about the Program.

Read more on course content , Details about the Program.

In next step covert each char to integer by int() function and then add them all to get the sum of the digits.

### Video Tutorial on Sum of digits of a number

```
n=input("Enter a Number :")
sum=0
for i in range(0,len(n)):
sum=sum+int(n[i])
print("sum of digits in number : ", sum)
```

Output
```
Enter a Number :549
sum of digits in number : 18
```

In above code we used len() to get the number of elements ( or char here ) in the string object If 4534 is divided by 10 then reminder is 4 ( the right most digit ).

The floor value of 4534 after the division by 10 will be 453, so we can loop through and find the floor values till the floor value became 0. Inside the loop we can get reminders as digits of the number. Here is the code.

```
n=int(input("Enter a Number :"))
sum=0
while(n>0):
i=n%10 # reminder value of division
sum=sum+i
n=n//10 # floor value of division
print("sum of digits in number=",sum)
```

Output
```
Enter a Number :1251
sum of digits in number=9
```

All Sample codesFibonacci series Factors of a number Factorial of a number Armstrong Number

This article is written by **plus2net.com** team.

Post your comments , suggestion , error , requirements etc here

Python Video Tutorials

Python SQLite Video Tutorials

Python MySQL Video Tutorials

Python Tkinter Video Tutorials