Hollow diamond in python with an asterisk outline
<p>I have to build a hollow diamond like this one:</p>

<pre><code>   ******
   **  **
   *    *
   *    *
   **  **
   ******
</code></pre>

<p>Heres what I have so far, </p>

<pre><code>def hollow_diamond(w):
 h=int(w/2)
 while 0&lt;h:
  print('*'*h)
  h=h-1
 i=1
 while i&lt;(w/2+1):
  print(i*'*')
  i=i+1
</code></pre>

<p>However using the code that i have i only get half of the diamond.</p>

<pre><code>***
**
*
*
**
***
</code></pre>

<p>Should I be using <strong>for</strong> loops instead of while to be able to complete the diamond?</p>

<p>Building a hollow diamond means, like you said, probably the following:</p>

<ol>
<li>A line with full asterisks (<code>0</code> spaces in the middle)</li>
<li>A line with <code>2</code> spaces in the middle</li>
<li>A line with <code>4</code> spaces in the middle</li>
<li>...</li>
<li>A line with <code>l-2</code> spaces in the middle</li>
<li>A line with <code>l-2</code> spaces in the middle</li>
<li>A line with <code>l-4</code> spaces in the middle</li>
<li>A line with <code>l-6</code> spaces in the middle</li>
<li>...</li>
<li>A line with full asterisks (<code>l-l</code> spaces in the middle)</li>
</ol>

<p><code>n</code> is the "step", or how many asterisks you "lose" in each iteration. <code>l</code> is the size of your square.</p>

<p>So, you algorithm is composed of two parts, the increasing spaces, and the decreasing spaces.</p>

<p>So, your algorithm should be something like this</p>

<pre><code>for (spaces = 0; spaces &lt; size/2 ; spaces = spaces + 1 ) 
    for (asterisk = 0; asterisk &lt; size/2 - spaces; asterisk = asterisk + 1)
        print '*'
    for (space = 0; space &lt; spaces*2; space = space + 1) 
        print ' '
    for (asterisk = 0; asterisk &lt; size/2 - spaces; asterisk = asterisk + 1)
        print '*'
for (spaces = size/2 - 1; spaces &gt;= 0; spaces = spaces - 1) 
    # The same inner code as above
</code></pre>

<p>I purposedly didn't put the python code there, so you can do your homework properly ;), but once you understand the algorithm, that should be pretty easy.</p>

python python-3.x