0

How can I made a sum like this 18 = 1 + 8 = 9?

I accept suggestion in all languages expecially ruby and python

7th Nov 2016, 5:09 PM
Etabeta1🇮🇹
Etabeta1🇮🇹 - avatar
2 Respostas
+ 3
string_number = str(18) sum = 0 for ch in string_number: number = int(ch) sum += number print sum
7th Nov 2016, 5:35 PM
Iqbal Mohammad Rhidwan
Iqbal Mohammad Rhidwan - avatar
+ 1
both in Python #1: number = 18 sum = 0 for char in str(number): sum += int(char) print(sum) #2: number = 18 sum = 0 while number > 0: sum += number % 10 number //= 10 print(sum)
7th Nov 2016, 5:39 PM
Demeth
Demeth - avatar