pyjama
pyjama

Reputation: 135

Remove new line from output

I have the below function:

i = 1
h_ = 4
for i in range(h_+1):
    w_i = " " * (h_ - i)
    h_i = "*" * i
    pyramid =  w_i + h_i
    print(pyramid)
i+1

Actual output:

$ python test.py

   *
  **
 ***
****

Expected output:

$ python test.py
   *
  **
 ***
****

How do I remove the new line at the beginning of the output?

Thank you

Upvotes: 0

Views: 40

Answers (1)

Arpit Maiya
Arpit Maiya

Reputation: 177

just make a small change in your for loop as below,

i = 1
h_ = 4
for i in range(1, h_+1):
    w_i = " " * (h_ - i)
    h_i = "*" * i
    pyramid =  w_i + h_i
    print(pyramid)

start the for loop with 1.

Upvotes: 1

Related Questions