
Andrew K.
asked 12/21/20Lab_Python_Assignment_12
Write a program that inputs an integer between 0 and 1000 and adds all the digits in the integer. For example, if integer is 634, the sum of all its digits is 13.
1 Expert Answer

Patrick B. answered 12/22/20
Math and computer tutor/teacher
num = 9999
while (int(num)>999) or (int(num)<1):
num = input("Please input number between 1-1000 :>")
N = len(str(num))
sum=0
for i in range(N):
sum = int(sum)+int(num[i])
print(' number is ' + str(num))
print(' sum is ' + str(sum))
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code posted in RESOURCES section under this link12/22/20