Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop help
#1
Hey everyone, have all of my code correct thus far (so I think lol) but steps 6 & 7 have me very lost. My instructor never gave us any information on swaps and I'm thinking there is to be a loop within a loop but i'm not sure if that is even possible with python. Appreciate any help/direction
  1. Draw five adjacent boxes and number the boxes 0 though 4

  2. Put the following numbers in boxes 0 - 4, one number per box: 6 8 4 5 2
  1. Draw a box, label the box I, write the number 0 in box I

  2. Draw a box, label the box J, write the number 999 in box J

  3. If the number in box I is less than 5 then do the next instruction, otherwise do instruction 12

  4. Replace the number in box J with 0

  5. If the number in box J is less than 4 then do the next instruction, otherwise do instruction 10

  6. If the number in the numbered box whose box number is the same as the number in box J is greater than the number in the box that follows then do the next instruction, otherwise do instruction 8

  7. Swap the value in the box whose box number is the same as the number in box J with the value in the box that follows

  8. Replace the number in box J with the number that is one more than the number currently in box J

  9. Go back and do instruction 5 again

  10. Replace the number in box I with the number that is one more than the number currently in box I

  11. Go back and do instruction 3 again

  12. You are done

list_ = [6,8,4,5,2]
I = 0
J = 999
while I < 5:
  J = 0
  while J < 4:
    
    
  J = J + 1
  I = I + 1
Reply


Messages In This Thread
while loop help - by jhall710 - Apr-25-2017, 09:36 PM
RE: while loop help - by Larz60+ - Apr-26-2017, 12:07 AM
RE: while loop help - by jhall710 - Apr-27-2017, 01:15 AM
RE: while loop help - by Larz60+ - Apr-27-2017, 01:58 AM
RE: while loop help - by smbx33 - Apr-27-2017, 07:28 AM
RE: while loop help - by jhall710 - May-07-2017, 08:05 PM
RE: while loop help - by ichabod801 - May-07-2017, 09:54 PM
RE: while loop help - by jhall710 - May-08-2017, 12:28 AM
RE: while loop help - by ichabod801 - May-08-2017, 01:12 AM
RE: while loop help - by jhall710 - May-08-2017, 02:20 AM
RE: while loop help - by smbx33 - May-08-2017, 08:59 PM
RE: while loop help - by volcano63 - May-08-2017, 09:25 PM
RE: while loop help - by ichabod801 - May-08-2017, 11:57 AM
RE: while loop help - by nilamo - May-08-2017, 04:41 PM
RE: while loop help - by volcano63 - May-08-2017, 08:00 PM
RE: while loop help - by ichabod801 - May-08-2017, 09:37 PM

Forum Jump:

User Panel Messages

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