iwrestledthebeartwice
iwrestledthebeartwice

Reputation: 734

How to print the hollow pyramid pattern?

So, I have this code

num = int(input("Enter the Number: "))

for i in range(1, num+1):
    for j in range(0, i):
        print(" ", end="")

    for j in range(1, (num*2 - (2*i - 1))+1):
        if i == 1 or j == 1 or j ==(num*2 -(2*i-1)):
            print("*", end="")
        else:
            print(" ", end="")
    print()

It gives the following output

 ***********
  *       *
   *     *
    *   *
     * *
      *

However, I want the following output with spaces on the first line

 * * * * * *
  *       *
   *     *
    *   *
     * *
      *

How do I do this? Any help would be appreciated, thanks

Upvotes: 0

Views: 2506

Answers (1)

iwrestledthebeartwice
iwrestledthebeartwice

Reputation: 734

Well, I found the answer, thank you @yudhiesh

line = int(input())
print(line * "* ")
for i in range(line-2,0,-1):
    print((line-i-1)* " " +  "*" + (2*i -1)*" " + "* ")


print((line-1 )* " " + "* ")

Upvotes: 2

Related Questions