Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop
#1
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

This is my code:

while mystery_int_1 >= 0 and mystery_int_2 >= 0 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)
But this is my output:

2 3 4
1 2 3
0 1 2

I have no clue what to do, I've tried a few other things but can't get it to work, I know it's insanely easy, but I can't figure it out

I figured it out, is there a way to just delete this thread?
Reply
#2
I'll only hint because it's homework, but it's because your loop stops once any of your numbers are 0. You need to end the loop when ALL the numbers are zero of less.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020