0

Run a while loop until all three values are less than or equal to 0. Every time you change the value of the three variables, print out their new values all on the same line, separated by single spaces. For example, if their values were 3, 4, and 5 respectively, your code would print:
2 3 4
1 2 3
0 1 2
-1 0 1
-2 -1 0

My code is:

    while (mystery_int_1 and mystery_int_2 and mystery_int_3) >= 0:
        mystery_int_1 -= 1
        mystery_int_2 -= 1
        mystery_int_3 -= 1
        print(mystery_int_1, mystery_int_2, mystery_int_3)

It produces:
2 3 4
1 2 3
0 1 2
-1 0 1
-2 -1 0
-3 -2 -1

I know the answer will make me feel like an idiot, but I can't figure this out

MojoMike
  • 33
  • 5
  • Your syntax isn't doing what you think it is. Change the `while` test to `while mystery_int_1 >= 0 and mystery_int_2 >= 0 and mystery_int_3 >= 0:` What you have now is checking to see if all three values are *non-zero*, then comparing that result (which will be the first 0 value, if any, otherwise the last (non-zero) value) with 0. Not what you want at all. – Tom Karzes Apr 16 '20 at 02:18
  • 1
    For example, try this: `(-1 and 1) >= 0`. It will be `True` since it is using the last non-zero value, `1`, in the comparison. But `-1 >= 0 and 1 >= 0` will be `False`, which is what you want. – Tom Karzes Apr 16 '20 at 02:20
  • Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – ApproachingDarknessFish Apr 16 '20 at 02:22
  • I changed it to while mystery_int_1 >= 0 and mystery_int_2 >= 0 and mystery_int_3 >= 0: and now it stops 1 line early instead of 1 line too late. – MojoMike Apr 16 '20 at 02:31

1 Answers1

0

Your boolean expression is wrong, try using this one and understanding why it works:

while (mystery_int_1 > 0 or mystery_int_2 > 0 or mystery_int_3 > 0) :

Using and is wrong because if one of the variables brakes the condition the loop stops but you want it to stop only if all the variables brake the condition. So, you use or.

Mahmood Darwish
  • 536
  • 3
  • 12