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>You've already figured out how to print the first set of asterisks for each line; good job so far.  Now, you need to figure out how many spaces to print.  Let's take the first loop, where you're printing <strong>h</strong> asterisks in a grid of <strong>w</strong> lines.</p>

<p>You need <strong>h</strong> asterisks on the left and <strong>h</strong> more on the right; that's <strong>2*h</strong> asterisks total.  This leaves <strong>s = w - 2*h</strong> spaces in the middle.</p>

<p>So, for each line, you need to print ...</p>

<ul>
<li><strong>h</strong> asterisks</li>
<li><strong>s</strong> spaces</li>
<li><strong>h</strong> more asterisks</li>
</ul>

<p>Does that move you toward a useful update of your current code?</p>

python python-3.x