Ask Question
10 February, 12:10

Write a Python program that asks the user to enter a series of single-digit numbers with nothing separating them.

The program should display the sum of all the single-digit numbers in the string.

For example, if the user enters 2514, the method should return 12, which is the sum of 2, 5, 1 and 4.

+2
Answers (1)
  1. 10 February, 13:27
    0
    The Python 3 code for the program described in the question:

    def sum_digits (str):

    sum = 0

    for c in str:

    sum + = int (c)

    return sum

    def main ():

    print ("Enter series of single-digit numbers with no spaces: ")

    str = input ()

    print ("The sum of digits of the entered number is", sum_digits (str))

    main ()
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a Python program that asks the user to enter a series of single-digit numbers with nothing separating them. The program should ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers