how to use for loop to create right angled triangle?
<pre><code>I want to print :
    1
   12
  123
 1234
</code></pre>

<p>and i have tried:</p>

<pre><code>num=int(input("number"))
space=int(num)
count=1
while count&lt;num:
  if count==1:
    print(" "*space,count)
    count=count+1
    space=space-1
    while count&gt;=2:
      for n in range(2,num):
        print(" "*space,list(range(1,n))
        space=space-1
</code></pre>

<p>But it doesn't work.
How can i print the designated result ?
Thanks</p>

<pre><code>print(" "*space,list(range(1,n))
</code></pre>

<p>Count the parentheses on this line.  One of them isn't closed, which it has to be to work as you intend. </p>

<p>Also note that your <code>while</code> loop will never stop running.</p>

<p>As a general rule of thumb, whenever you know exactly how many times you should do something, you should use a <code>for</code> loop instead of a <code>while</code> loop</p>

<p>Let's try to rewrite you code using a <code>for</code> loop:</p>

<pre><code>num=int(input("number"))
output = ""
for n in range(1,num+1):
    output = ''.join([output, str(n)])
    space = ' ' * (num - len(output))
    print(space, output, sep='')
</code></pre>

<p>The only real substantive change I made other than a <code>for</code> loop is treating the output as a string rather than a list of numbers. </p>

python