'print a pyramid with hash blocks

Im stuck with my code. I have to build a pyramid with hash blocks the first row has to start with 2 hash blocks. Every row beneath + 1. How do I implement this program

height = input("What height should the pyramid be?")
height = int(height)

while height > 23 :
    height = input("What height should the pyramid be?")
    height = int(height)

for i in range(0, height):
    print("#" * height)

print()


Solution 1:[1]

After a while of thinking, I found your code. This will not create a triangle or any of the sort but it will create a proper pyramid:

height = int(height)

while height > 23:
    height = input("What height should the pyramid be?")
    height = int(height)
c = height

for j in range(height):
    for i in range(j):
        print("#", end="    ")
    height -= 1
    print()
    for h in range(c):
        print("  ", end="")
    c -= 1

Here what I have done is, first get the number of spaces needed to enter in the start of the line. Then it will enter the number of hashes required for the pyramid and it will repeat this until the final pyramid is made. But just be careful, you have to enter one number plus the number of the pyramid rows you want. Otherwise it will create a pyramid of the number -1. So you can change the code in the for loop by doing height+1 or you could just leave it like that.

Solution 2:[2]

height = input("What height should the pyramid be: ")
height = int(height)

for i in range(0, height):
    for j in range(0,i):
        print("#",end =" ")
    print()

This is the right loop.

output:

What height should the pyramid be: 9
# 
# # 
# # # 
# # # # 
# # # # # 
# # # # # # 
# # # # # # # 
# # # # # # # # 

EDIT FOR PYRAMID NOT A TRIANGLE

rows = int(input("Enter number of rows: "))

k = 0

for i in range(1, rows+1):
    for space in range(1, (rows-i)+1):
        print(end="  ")
   
    while k!=(2*i-1):
        print("* ", end="")
        k += 1
   
    k = 0
    print()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2