You're the man! no wonder you are the minister of silly walks.
So shout out to jefsummers.
I can rest this program in peace now.
# Creat main func. to process input int.
def main():
# Create list that holds multiple processed inputs to output together.
output = []
# Start try/except block to deal with error codes.
try:
# Create user input with direction for int.
user_input = input('Enter a sequence of digits with nothing separating '
'them (no input terminates): ')
# Create while loop with with sentinel to iterate user input.
while user_input != '':
# Create variable that contains message with input and calls
# stringTotal passing user input.
output_accumulator = ('The sum of input string ['+ user_input+ '] is: '+
str(stringTotal(user_input)))
# Add output_accumulator to output list.
output.append(output_accumulator)
# Repeat user input to complete loop
user_input = input('Enter a sequence of digits with nothing '
'separating them (no input terminates): ')
if user_input == '': # Create if statement with no input to
raise EOFError # raise EOFError.
except ValueError: # Create exception clause for ValueError
# Create message for ValueError
print('ERROR enter only numbers with no spaces.')
except EOFError: # Create exception clause for EOFError
# Create header + what program does.
print ('\n\n\nWelcome to the Sum of the Digits Program \n\n'
'This program will sum the digits of an input string.\n')
# Call output and iterate its list.
for x in output:
print(x)
# Create end message.
print('\n\n*** Program has completed successfully***')
def stringTotal(user_input): # Create strinTotal() recieving user_input.
total = 0 # Create accunulator variable.
for num in user_input: # Create for loop to iterate user_input.
# Create variable that holds user_input string turned into int.
numbers = int(num)
total += numbers # Add int. in total variable.
return total # Return total.
main() # Call main
Output:
Welcome to the Sum of the Digits Program
This program will sum the digits of an input string.
The sum of input string [12345] is: 15
The sum of input string [123456789] is: 45
*** Program has completed successfully***