I took this from a recent thread, to show you how you can use a temporary print statement to figure out what is going on ...
# create a jumbled word/string
import random
# create a sequence, here a tuple, of words to choose from
WORDS = ("python", "jumble", "easy", "difficult", "answer", "babysitter")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create a jumbled version of the word
# start with an empty string to be built up in the while loop
jumble = ""
# word is reduced in size by one character each time through the loop
# when it is empty it will be equal to None(False) and the loop stops
while word:
print word,' ', jumble # for test only
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
print jumble # now you can ask to guess the word ...
Just a little note, when you save this code, don't save it as random.py. Python will confuse this in the import statement! It will look for the module random.py in the working directory first, before it goes the \Lib directory where the proper module is located.
Last edited by vegaseat : Mar 1st, 2007 at 3:41 pm. Reason: [code=python] tag
May 'the Google' be with you!