[Tutor] Random order program

myles broomes mylesbroomes at hotmail.co.uk
Sun Nov 27 23:17:28 CET 2011


I requested help for this code earlier and I thought it had been corrected but apparently, there is still a problem with it...

#random word order program
#the user gives the program a list of words
#the program then returns them in a random order

import random

#explain the purpose of the program to the user
print("At the prompt, type in a list of words and they will be returned in a random order.")

#get the users input for the list of words, one by one
first_word = input("Please enter your first word: ")
second_word = input("Please enter your second word: ")
third_word = input("Please enter your third word: ")
fourth_word = input("Please enter your fourth word: ")
fifth_word = input("Please enter your fifth word: ")

#create a tuple containing the users words of the words
word_list = (first_word,second_word,third_word,fourth_word,fifth_word)

#create an empty list that the words will go into to be returned in a random order
random_word_list = []

print("Now your list will be displayed in a random order.")

#random order list
while len(random_word_list) != len(word_list):
        word = random.choice(word_list)
        if word not in random_word_list:
                random_word_list += word

#display the random word list
print(random_word_list)

input("Press enter to exit...")

And once again, the following is displayed....

At the prompt, type in a list of words and they will be returned in a random order.
Please enter your first word: one
Please enter your second word: two
Please enter your third word: three
Please enter your fourth word: four
Please enter your fifth word: five
Now your list will be displayed in a random order.

Then the program just stops for some reason. Again, any help is much appreciated.



More information about the Tutor mailing list