How to separate numbers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to separate numbers?

Example: Input: 123 Output: 1 2 3

15th Dec 2021, 10:51 AM
Quarkom
3 Answers
+ 3
Convert it into string using str(num) function then use run a for loop: Code for i in str(num): print(i)
15th Dec 2021, 10:54 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Quarkom Ok then declare a variable with value 0 outside the loop and within the loop convert single digit again into intiger using int function and add them to declared variable like variable+=int(i) That's all
15th Dec 2021, 11:13 AM
Ayush Kumar
Ayush Kumar - avatar
0
丹ⓨㄩک廾 I mean, I would like to sum up all of digits 1,2,3 after
15th Dec 2021, 10:57 AM
Quarkom