New course! Every coder should learn Generative AI!
Try a free lesson0
qw="2,4,3.56,6,7" d=qw.split(',') print(d) c="+".join(d) print(c) w=float(d) for i in d: print(sum(w))
How to add the elements in qw, what's wrong in above code.
3 Answers
0
qw="2,4,3.56,6,7"
d=qw.split(',')
print(d)
c="+".join(d)
print(eval(c))
This evaluates it
0
This is one way. Your list of strings need to be converted to float before you iterate over it. https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-converting-all-strings-in-list-to-integers/
sum=0
for i in d:
sum+=float(i)
print(sum)
0
Thank you,I understand now