Functions · 15 / 27 Exercise Medium

Function to sum the digits of a number

Objective

Develop a Python program that asks the user for a number and stores it as text. Then, implement a function called sum_digits that receives the text and returns the sum of its digits.

Instructions

  • In the main function, ask the user for a number and keep it as a text.
  • Implement the function sum_digits with the text as a parameter. It adds up the digits and returns the result.
  • Print the result with a message indicating that it is the sum of the digits of the number.
Input
2222222222222222222222
Output
The sum of the digits is: 44

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise