Python Forum
sum - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: sum (/thread-25171.html)



sum - dansht - Mar-22-2020

i write this ode :
a = [1,2,3]
b = [4,5,6]
ab=[]
for i in range(0, len(a)) : 
    ab.append(a[i]*b[i])
print(ab)

and get :
Output:
[4, 10, 18]
now i trying to add 4+10+18 but dont know how to do it
please help


RE: sum - ndc85430 - Mar-22-2020

What have you thought about? Programming is an exercise in problem solving, so work it out! How would you work it out on paper?


RE: sum - snippsat - Mar-22-2020

(Mar-22-2020, 01:43 PM)dansht Wrote: now i trying to add 4+10+18 but dont know how to do it
You have already written part of the answer in Thread title,just missing (your_list) Think


RE: sum - dansht - Mar-22-2020

can someone help ?


RE: sum - snippsat - Mar-22-2020

So the hint was that you had written the first part in Title sum.
>>> ab = [4, 10, 18]
>>> sum(ab)
32