divide a string into two halves in python : <p>this is my question:</p>

<pre><code>F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front   half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 strings, a and b, return a string of the form
#  a-front + b-front + a-back + b-back
</code></pre>

<p>and this is my answer:</p>

<pre><code>def front_back(a, b):
  s = ""
  if len(a) % 2 == 0:
      s = s + a[:len(a) / 2]
      if len(b) % 2 == 0:
          s = s + b[:len(b) / 2]
          s = s + a[len(a) / 2:]
          s = s + b[len(b) / 2:]
      else:
          s = s + b[:len(b) / 2 + 1]
          s = s + a[len(a) / 2 + 1:]
          s = s + b[len(b) / 2 + 1:]
  else:
      s = s + a[:len(a) / 2 + 1]
      if len(b) % 2 == 0:
          s = s + b[:len(b) / 2]
          s = s + a[len(a) / 2:]
          s = s + b[len(b) / 2:]
      else:
          s = s + b[:len(b) / 2 + 1]
          s = s + a[len(a) / 2 + 1:]
          s = s + b[len(b) / 2 + 1:]
  return s
</code></pre>

<p>this answer isn't work on all strings and i don't understand what is the problem.</p>
