0

How to separate integer and perform calculation separately?

Example x= (1798) #i want to add each number separately with each other x=1+7+9+8 print (x) output 25 I know this is pretty basic but i really don't find any solution of this.

8th Jun 2018, 2:30 PM
Gagan Deep Singh
Gagan Deep Singh - avatar
4 Answers
+ 2
Gagan Deep Singh use "join" x = 1798 y = "+".join(x) # "1+7+9+8" now this is a string use "eval" to solve math equations which are in string. line this. print(eval(y)) output = 25
9th Jun 2018, 3:25 PM
Salman
Salman - avatar
8th Jun 2018, 2:36 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
https://code.sololearn.com/c1I7VyvdqUZw/?ref=app
8th Jun 2018, 2:43 PM
TurtleShell
TurtleShell - avatar