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.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417