How to make loop repeat until the sum is a single digit?
<p>Prompt: Write a program that adds all the digits in an integer. If the resulting sum is more than one digit, keep repeating until the sum is one digit. For example, the number 2345 has the sum <code>2+3+4+5 = 14</code> which is not a single digit so repeat with <code>1+4 = 5</code> which is a single digit.</p>

<p>This is the code I have so far. It works out for the first part, but I can't figure out how to make it repeat until the sum is a single digit. I'm pretty sure I'm supposed to nest the code I already have with another <code>while</code> statement</p>

<pre><code>n = int(input("Input an integer:"))
sum_int=0  
while float(n)/10 &gt;= .1:   
    r= n%10
    sum_int += r
    n= n//10   
    if float(n)/10 &gt; .1: print(r,  end= " + ") 
    else: print(r,"=",sum_int)
</code></pre>

<p>this is a sample output of the code</p>

<p>Input an integer: 98765678912398</p>

<p>8 + 9 + 3 + 2 + 1 + 9 + 8 + 7 + 6 + 5 + 6 + 7 + 8 + 9 = 88</p>

<p>8 + 8 = 16</p>

<p>1 + 6 = 7</p>

<p>If you like <strong>recursion</strong>, and you must:</p>

<pre><code>&gt;&gt;&gt; def sum_digits_rec(integ):
        if integ &lt;= 9:
            return integ
        res = sum(divmod(integ, 10)) 
        return sum_digits(res)

&gt;&gt;&gt; print(sum_digits_rec(98765678912398))
7
</code></pre>

python