Creating a triangle of characters from a users input
<p>For an assignment I'm suppose to make a triangle using the users input if the characters are equal to an even number. The triangle is suppose to print up to 5 lines in height and the left of it should be the left half of the string and the right side of the triangle should be the right side of the string. </p>

<p><a href="http://i.stack.imgur.com/zM10K.png" rel="nofollow">Example of what the triangle is suppose to look like</a></p>

<p>The problem is I can't figure out how to divide my triangle in half without hard coding it or how to properly display the white space without a loop (were not allowed to in the assignment). Right now if I were to put in "ab" it would return:</p>

<pre><code>     aabb
    aabbaabb
   aabbaabbaabb
  aabbaabbaabbaabb
 aabbaabbaabbaabbaabb
</code></pre>

<p>Instead of:</p>

<pre><code>         aabb
       aaaabbbb
     aaaaaabbbbbb
   aaaaaaaabbbbbbbb
 aaaaaaaaaabbbbbbbbbb
</code></pre>

<p>Here's my code: </p>

<pre><code>#GET Users String
userString = input("Please enter a string with a value of 7 or less characters: ")

#CALCULATE IF userString is less than or equal to 7 and is even 
if len(userString) &lt;= 7 and len(userString) % 2 == 0:
    print (" " * 5 + userString)
    print(" " * 4 + userString * 2)
    print(" " * 3 + userString * 3)
    print(" " * 2 + userString * 4)
    print(" " + userString * 5)

#CALCULATE IF userString is less than 7 but and off 
elif len(userString) &lt;=7 and len(userString) % 2 == 1:
    print("You are odd")

#CALCULATE IF userString is over 7 characters
else:
    print ('The string is too long. \nGood-bye!')
</code></pre>

<p>Here's how you can do this:</p>

<pre><code>def print_next(st, index):
   if index &lt; 6:    # have not reached 5 - print offset and string
      offset = 6-index
      print '  '*offset+st
      index=index+1   # increase counter
      print_next((st[0:2]+st[-2:len(st)])*index,index) # recursively go next


print_next('aabb',1) # initial call with index set to 1
</code></pre>

python