Sunday, December 26, 2021

Sum of Digits in Python

 Machine Problem

Design a program that will ask the user to give a number and then the program will compute the sum of all the digits of the given
number using for loop statement.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Program Listing

#
# Machine Problem
#
# Design a program that will ask the user to give a number and then
# the program will compute the sum of all the digits of the given
# number using for loop statement.

print()
print("\tSum of Digits in Python")
print()

num=int(input("Enter number : "))

sum=0

for digit in str(num):
sum=sum+int(digit)

print()
print("The Sum of Digits is %d." %(sum))
print("\n\tEnd of Program")

No comments:

Post a Comment