Ask Question

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.

+1
Answers (1)
  1. 17 June, 10:39
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers