7 odpowiedzi
+ 4
sum([1,2,3,4,5])
+ 4
Use sum function
sum(A)
or
use the following:
_sum = 0
for i in A:
_sum += 1
print(_sum)
+ 3
Using the built in function sum: https://www.geeksforgeeks.org/sum-function-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/
Iterate and accumulate: https://stackoverflow.com/questions/14555263/print-the-sum-of-a-list-of-integers-without-using-sum
+ 3
It can be done by two ways:
M1- using predefined function.
A=[]
Print(sum(A))
M2- creating a program.
A=[]
Sum=0
for num in A:
Sum+= num
#add each num after num
print(sum)
0
sum(A)