title: Python Word Scramble/Jumble - how does this scramble a word?
body: <p>I have a python program here that unscrambles a word, but I'm not sure what is happening in a specific section. </p>
  
  <p>In the section that is blockquoted and separated by headers below, I don't understand why the 'scrambling' of the word is put into a while loop - could it not work without the loop? Also, can someone explain everything happening inside of that while loop (while word:)?</p>
  
  <pre><code>import random
  words = ('coffee', 'phone', 'chair', 'alarm')
  word = random.choice(words)
  
  correct = word
  scramble = ""
  </code></pre>
  
  <hr>
  
  <blockquote>
  <pre><code>while word:
      position = random.randrange(len(word))
      scramble += word[position]
      word = word[:position] + word[(position + 1):]
  </code></pre>
  </blockquote>
  
  <hr>
  
  <pre><code>print("The scrambled word is: ", scramble)
  answer = input("What's your guess?: ")
  
  def unscramble(answer):
      while answer != correct and answer != "":
          print("Sorry, incorrect.")
          answer = input("Try again: ")
      if answer == correct:
          print("Good job, that is correct!")
  
  unscramble(answer)
  </code></pre>