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.
4 Réponses
+ 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
+ 1
like this...?
https://code.sololearn.com/cRjz3Cd2qb0G/?ref=app
+ 1
https://code.sololearn.com/c1I7VyvdqUZw/?ref=app