Many times you can insert a temporary print statement to show what is going on. Here a test print inside the loop ...
import random
# create a sequence of words to choose from
WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")
# 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
jumble =""
while word:
print word,' ', jumble # for test only
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
print jumble
The empty string would return a None (Python's version of NULL) which is evaluated as boolean False, so the loop stops.
Last edited by vegaseat; Aug 12th, 2009 at 12:59 pm.
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
Offline 5,792 posts
since Oct 2004