Python program to print the sum of all digits in a given number
kw.py
print("___________________________________________")print("Program to print sum of all digits")print("___________________________________________")try:n=int(input("Enter the number "))if(n<=0):print("Please enter a positive number")else:sum=0temp=nwhilen>0:r=n%10sum=sum+rn=n//10print("Sum of all digits in",temp,"is",sum)exceptValueError:print("Enter valid number")print("___________________________________________")
Output
kodingwindow@kw:~$ python3 kw.py
___________________________________________
Program to print sum of all digits
___________________________________________
Enter the number 123456789
Sum of all digits in 123456789 is 45
___________________________________________
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?