Looking to create a horizontal pyramid that takes height as an argument for the length of the base of the triangle, and incrementally increases the value in the vertical direction before moving to the next horizontal row.
I have tried the following code:
def triangle(height):
count=0
for i in range(height//2):
count+=1
for j in range(i+1):
print(count+count*j,end=' ')
print()
for i in range((height-1)//2,-1,-1):
count+=1
for j in range(i+1):
print(count+count*j,end=' ')
print()
The above does not seem to be working to achieve the correct result for heights greater than 3:
examples of the shape I would like to print:
triangle(4)
1
2 5
3 6
4
triangle(5)
1
2 6
3 7 9
4 8
5
Any help appreciated.