[Tutor] Random order program

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


Im trying to make a program where the user enters 5 words and then the list of words a is returned in a random order. Heres the code I have come up with so far:

#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 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...")

When I run the program, this is what 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.


...And then nothing happens after that - no error, no nothing. Any help would be much appreciated.
Thanks in advance.



More information about the Tutor mailing list