0
print('1+2+3+4.0+5')=?
5 Answers
+ 5
Avalon š
x = '1+2+3+4.0+5'
print(eval(x))
+ 3
Output:
1+2+3+4.0+5
+ 2
You can go on with Namit Jain answer.
Since the value in print() function is given as a string.
print('1+2+3+4.0+5') = 1+2+3+4.0+5
It can be summed only if we don't use the quotes " " or else we can use this string inside eval() method.
print(eval('1+2+3+4.0+5')) = 15.0
+ 1
It is string as it is in quotes.
Output: 1+2+3+4.0+5
+ 1
x='1+2+3+4.0+5'
z=0
for i in x.split('+'):
z+=float(i)
print(int(z))
m=[float(i) for i in x.split('+')]
print(sum(m))