Search code examples
pythonintegeradditiondigit

Python - How to show addition of integers digits


I want to show in a line the addition of the digits of a positive integer. For example if input is

4316

I want it to output

4+3+1+6

Also the input can be any x amount of digits.


Solution

  • Call stron the number and str.join the result of that:

    i = 4316
    
    print("+".join(str(i)))
    4+3+1+6