-1

Program to print following:

   *
  **
 ***
****

My program:

for i in range(1,5):
    for j in range(1,5-i):
        print '',
    for k in range(1,i+1):
        print "*",
    print 

It prints:-

   *
  * *
 * * *
* * * *

What is the problem?

Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
  • Possible duplicate of [How do I keep Python print from adding newlines or spaces?](http://stackoverflow.com/questions/255147/how-do-i-keep-python-print-from-adding-newlines-or-spaces) – Łukasz Rogalski Sep 20 '16 at 12:54

1 Answers1

0

Python will add new space between two print " ",
Simplify version:

for i in range(1,5):
    print " " * (5 - i) + "*" * i
Grey Li
  • 11,664
  • 4
  • 54
  • 64