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.