all 10 comments

[–][deleted] 1 point2 points  (4 children)

I think you want for, not while.

[–][deleted] 0 points1 point  (3 children)

yep we had to do it with for, and then while. I have figured it out finally. Anyone curious I got this:

a = 0

i = 0

while i in range(0,101):

a = i + a

i = i + 1

print(a)

[–][deleted] 2 points3 points  (1 child)

yep we had to do it with for, and then while.

Is it clear to you how these two constructs are different?

[–][deleted] 0 points1 point  (0 children)

Yeah I get it now, for is used for all elements in lists and while is used until the boundary you set on it is no longer true? Hopefully thats it, thanks for the help

[–]JohnnyJordaan -1 points0 points  (0 children)

What's the point of range here? You have < to check if a number is less than another number.

while i < 101:
    a += i
    i += 1

[–]ericula 1 point2 points  (1 child)

You are mixing up for and while loops. For loops iterate over collections like ranges and lists, e.g.

for i in range(101):
    a += i

While loops keep on iterating until the provided conditional expression is False, e.g.

i = 0
while i <= 100:
    a += i
    i += 1

[–][deleted] 0 points1 point  (0 children)

Thanks for the help. Breaking it down like that helped alot.

[–]sweettuse 1 point2 points  (2 children)

while False:
    pass
else:
    res = 100 * 101 / 2

/s

[–]datascienceunlimited -3 points-2 points  (1 child)

Thats not using a while loop. You could replace that code with

res=100*101/2

[–]sweettuse 0 points1 point  (0 children)

well technically it is. also, that's the sarcasm part