Start New Discussion within our Software Development Community

I know python has math functions like 5+6 and 5*6 and 5/6 etc...but I have something like this:

and need to add them all together:

We help those who show a little effort at first.

Hint, convert x to a string and iterate the string summing up the int value of each character.

Something like this will work, I just have to get it to the point that it does it without the 'raw_input'......

>>>sum([int(i) for i in raw_input("Enter integer: ")])
Enter integer:1234567

Wait, I think I've got it:

>>>sum(int (i) for i in str(x)])
This article has been dead for over six months. Start a new discussion instead.