+ 1

Is there a way to add All the numbers in an array

I want write a script that can add all the number so in an array Array = [ 1, 2, 3, 4, 7, 9]

8th Feb 2019, 5:01 PM
Sonicspeed^__^
Sonicspeed^__^ - avatar
4 Respuestas
+ 3
print(sum(array))
8th Feb 2019, 5:44 PM
Diego
Diego - avatar
+ 2
I think this code will do what you want. https://code.sololearn.com/cvi8veJ9CxlB/?ref=app
8th Feb 2019, 5:17 PM
Maias Alakramy
+ 1
Look into List Comprehension... It allows you to make a list with whatever, on the fly.. For Example... Numbers = [I for I in range(100)] That above code would create an array called numbers and give it [0,1,2,3,4,5,etc] ... You can even change the parameters... oddNumbers=[i for i in range(100) if i%2!=0] Here is a code I wrote with examples of different uses... https://code.sololearn.com/c195fjflDL5F/?ref=app
8th Feb 2019, 5:04 PM
LordHill
LordHill - avatar
0
Thanks Maias Alakramy exactly what I was looking for
8th Feb 2019, 7:06 PM
Sonicspeed^__^
Sonicspeed^__^ - avatar