title: Pattern in Python: diamond of stars
body: <p>Loops question in Python:</p>
  <pre class="lang-py prettyprint-override"><code>n=int(input())
  k=n//2
  y=k+1
  
  for i in range(0,y):
      for j in range(0,y-i):
          print(&quot; &quot;,end='')
          
      for j in range(0,i):
          print(&quot;*&quot;,end='')
          
      for j in range(0,i-1):
          print(&quot;*&quot;,end='')
      print()
      
  for i in range(0,k):
      for j in range(0,i):
          print(&quot; &quot;,end='')
          
      for j in range(0,k-i+1):
          print(&quot;*&quot;,end='')
          
      for j in range(0,k-i):
          print(&quot;*&quot;,end='')
      print()
  </code></pre>
  <p>How can I rectify my code? It shows extra space and a star is missing in the end.</p>
  <p>Output for <code>input=5</code>:</p>
  <pre class="lang-none prettyprint-override"><code>  *
   ***
  *****
   ***
  </code></pre>
  <p><img src="https://i.stack.imgur.com/1OvJj.png" alt="enter image description here" /></p>
  <p>Here this code is right in while loop: but not working here in for loop</p>
  <pre><code>n=int(input())
  i=1
  k=n//2
  y=k+1
  while(i&lt;=y):
     
      j=1
      while(j&lt;=y-i):
          print(&quot; &quot;,end='')
          j=j+1
      j=1
      while(j&lt;=i):
          print(&quot;*&quot;,end='')
          j=j+1
      j=1
      while(j&lt;=i-1):
          print(&quot;*&quot;,end='')
          j=j+1
          
      print()
      i+=1
  i=1
  while(i&lt;=k):
      j=1
      while(j&lt;=i):
          print(&quot; &quot;,end='')
          j=j+1
          
      j=1
      while(j&lt;=k-i+1):
          print(&quot;*&quot;,end='')
          j=j+1
      j=1
      while(j&lt;=k-i):
          print(&quot;*&quot;,end='')
          j=j+1
            
      print()
      i=i+1
  </code></pre>
  <p>What is the difference between two codes?</p>