0

I don't know where is the mistake...

i=int(input()) while 100000>i>0: i=int(i/10000)+int((i%10000)/1000)+int((i%1000)/100)+int((i%100)/10)+(i%10) if i>9: continue if i<+9: break print(i)

19th Oct 2016, 9:55 AM
Algernon
Algernon - avatar
5 Answers
+ 4
https://code.sololearn.com/cT6KM53oE2h9 i = int(input()) n = 0; while i > 0: n += i%10 i //= 10 if i == 0 and n > 9: i = n n = 0 print(n)
19th Oct 2016, 10:40 AM
Zen
Zen - avatar
+ 1
why did you use a while loop?(BTW code you posted is not indented correctly) what did you meant to do in this program?
19th Oct 2016, 10:24 AM
Sunera
Sunera - avatar
+ 1
i=input().strip() sum=0 while True: sum=0 for c in list(i): sum+=int(c) if sum<10: break else : i=str(sum) print(sum)
19th Oct 2016, 10:42 AM
Sunera
Sunera - avatar
0
I want to find the sum of each digit. If the sum is greater than 9, find the sum of its bits. Until the sum is a single digit. Sorry, my English is not good.
19th Oct 2016, 10:32 AM
Algernon
Algernon - avatar
0
Thank you! I got it.
19th Oct 2016, 10:41 AM
Algernon
Algernon - avatar