title: Python Scrambler Program
body: <p>This program takes words in a sentence and scrambles them.
  The rules are:
  - first and last letter remain the same
  - punctuation at the end of a word stays the same
  - punctuation with a word is scrambled like the middle letters</p>
  
  <p>My problem is that if I have multiple punctuation at the end of a word it does not scramble it.</p>
  
  <p>Ex) testing!!! should be something like t!ste!nig! or t!est!nig!
  but not tstenig!!!</p>
  
  <p>How can I fix that?</p>
  
  <pre><code>import random
  import string
  
  original_text = input("Enter your text: ").split(' ')
  seed = int(input("Enter a seed (0 for random): "))
  
  punctuation = []
  for c in string.punctuation:
      punctuation.append(c)
  
  if seed is not 0:
      random.seed(seed)
  
  randomized_list = []
  
  def scramble_word(word):
      alpha = word[0]
      end_punctuation = ''
  
      if word[-1] in punctuation:
          x = -1
          while word[x] in punctuation:
              end_punctuation += word[x]
              x -= 1
          omega = word[x]
          middle = word[1: x]
      else:
          omega = word[-1]
          middle = word[1:-1]
          end_punctuation = ""
      middle_list = list(middle)
      random.shuffle(middle_list)
      shuffled_text = "".join(middle_list)
      new_words = alpha + shuffled_text + omega + end_punctuation
      return new_words
  for item in original_text:
      if len(item) &lt;= 3:
          randomized_list.append(item)
      else:
          randomized_list.append(scramble_word(item))
  new_words = " ".join(randomized_list)
  print(new_words)
  </code></pre>