Welcome folks today in this blog post we will be compute sum of digits of number in python.
All the full source code of the application is given below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 |
n=int(input("Enter a number:")) tot=0 while(n>0): dig=n%10 tot=tot+dig n=n//10 print("The total sum of digits is:",tot) |
Now if you execute the python
script by typing the below command as shown below
python app.py