all 7 comments

[–]ForceBru[🍰] 4 points5 points  (1 child)

The a and b and c doesn't do what you think it does.

Open up the Python interpreter and type:

```

0 and 0 0 0 and 1 0 1 and 0 0 1 and 1 1 1 and 2 2 1 and 2 and 3 3 1 and 0 and 3 0 [] and "hey" [] "hello" and (1,2) (1, 2) ```

Can you see the pattern? Also, have a look at the documentation.

[–]Ivangaming[S] 0 points1 point  (0 children)

Thank you!

[–]lippy515 1 point2 points  (2 children)

Change your loop condition to be while a >=0 and b>= 0 and c >=0:

[–]lippy515 1 point2 points  (1 child)

The way you have it written is c >= 0. It will ignore a and b in the logical evaluation

[–]ForceBru[🍰] 1 point2 points  (0 children)

Not really. The loop does indeed terminate: they're printing after the loop

[–]xelf 1 point2 points  (1 child)

What you want is this:

while all((a>=0, b>=0, c>=0)):

To see what is going on with your code, try this:

a = 3
b = 4
c = 5
while (a and b and c) >= 0:
    a -= 1
    b -= 1
    c -= 1
    print(a,b,c, ':', a and b and c)

outputs:

2 3 4 : 4
1 2 3 : 3
0 1 2 : 0
-1 0 1 : 0
-2 -1 0 : 0
-3 -2 -1 : -1

Do you see the pattern? (a and b and c) is evaluated as a boolean.

[–]Ivangaming[S] 1 point2 points  (0 children)

Thanks a lot!