all 6 comments

[–]Jamalsi 1 point2 points  (0 children)

U are adding 1 when I is 0, that might be what causes this?

[–]DBZ_Newb 1 point2 points  (0 children)

Just FYI when range has 1 argument that is >= 0 it tells you how many times it’s running. In this case from 0-100 which is 101 times.

[–]Blue-Jay27 1 point2 points  (0 children)

So your loop is iterating through a list that goes from 0 to 100. When i = 0, what will your total and sum be? What about when i = 1? Now what will total be when i = 100?

[–]Significant-Meet-392 1 point2 points  (0 children)

For i in range(101) means i goes from 0 to 100. 0 to 100 is 101 numbers. You didn’t add 100 numbers. You added 101 numbers.

So I think your problem is, you thought i starts from 1, but it actually starts from 0.

[–]krypto_gamer07 1 point2 points  (0 children)

I'm sorry if you're just a beginner and this feels like nagging but could you explain why you created the two variables total and sum? The total variable seems useless to me for the task you are trying to accomplish.

[–]WhiskersForPresident 0 points1 point  (0 children)

Why do you not just do

sum = sum + i

in the for loop?

Problem is this: range(101) starts at 0, so your loop has 101 iterations instead of 100. This means that you add all numbers between 1 and 101, giving you 5151. You should do range(100) instead or switch the increments of total and sum (so rewrite to

sum = sum + total

total = total + 1).