Implement a function that meets the specifications below.

def sum_digits(s):
""" assumes s a string
Returns an int that is the sum of all of the digits in s.
If there are no digits in s it raises a ValueError exception. """
# Your code here
For example, sum_digits("a;35d4") returns 12.

Paste your entire function, including the definition, in the box below. Do not leave any debugging print statements.

Respuesta :

Let me help you!
Since you did not specify what progamming languageĀ to use, I will do it in JAVA :>

import javax.swing.JOptionPane

public class Sum //The name of your program is Sum
{
//Variable Declaration
int s, sum, fCONTROL, control;

control = Integer.parseInt(JOptionPane.showMessageDialog("Please enter how many times you want to enter a number));
for(fCONTROL = 0; fCONTROL < control; fCONTROL++) //This is a for loop
{
//INPUT STATEMENT
s = Integer.parseInt(JOptionPane.showInputDialog("Please enter a number));
//PROCESS STATEMENT
sum = sum + s;
}//End of for loop
//OUTPUT STATEMENT
if(sum%2==0 || sum%2!=0)
{
JOptionPane.showMessageDialog(sum);
}
else
JOptionPane.showMessageDialog("You did not input an integer!");

}//End of program

You can test this is JCreator; it works and i stand by it. Good luck!
ACCESS MORE
EDU ACCESS
Universidad de Mexico