1

My project is currently just printing off a list of different string values inside a list. Each time a user types in 'enter' when prompted by the input, the for loop iterates and is suppose to show different orders of what they put in. For some reason, after the first time I type enter at the input prompt, it doesn't show the list. I basically just want the list to be reordered 5 times and then the loop all together stops. Here's the code and hopefully it will be come clear what I'm trying to do.

   import random

print('\t\t\tHOWDY! This is my go to for the homework. Give it a shot and let me know what you guys think')
print('\n\n\tRight down below is an input that will prompt you guys to add in about 5 different words. After that, it will print off different orders of this program 5 times.')

random_stuff = ''
length = 0

while not random_stuff:
    random_stuff = input('\nPlease add in a word to start: ')

input('\nPress enter to continue')

random_stuff = random_stuff.split()

print('\nNow lets add in 4 more words')

while len(random_stuff) < 5:
    random_stuff.append(input('\nPlease input a new phrase: '))

print('\nOkay so here is your list in the order it was received.')

input('\nPress enter to continue')

for x in range(len(random_stuff)):
    print(random_stuff[x], end=' ')

print('\nNow lets see it in a random order. Please type in enter when prompted by the command. This will be done 5 times')

while length < 5:
    press_enter =input('\nType enter to see what happens: ')
    press_enter = press_enter.lower()
    if press_enter == 'enter' and length < 5:
        for x in range(len(random_stuff)):
            random_order = random.randrange(len(random_stuff))
            print(random_stuff[random_order], end=' ')
            del(random_stuff[random_order])
    length += 1
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a [mcve]. – cs95 Oct 04 '17 at 01:54
  • You're deleting items in the list as you iterate over it. Bad move. – cs95 Oct 04 '17 at 01:56

0 Answers0