0
otal= 0 for i in [1,2,3,4,5] : total=total+1 print(total)
It give output 5.is it counting total elements of list
2 Answers
+ 2
Yes, total = total + 1
0=0+1
2=1+1
3=2+1
4=3+1
5=4+1
if you want to sum the elements, try:
total=total+i
+ 1
Yes, since you increase the value of total by 1 and not by the value. To get the sum you'll need to sum up:
list = [ 1, 2, 3, 4, 5 ];
... loop ...
total += list[index]
Hot today
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
2 Votes
Python palindrome challenge.
1 Votes
Java
0 Votes
Number of Ones ( C++ ) question!
1 Votes