Reputation: 55
I need some help trying to solve this, right now it keeps printing vertically only
height = int(input("Height of triangle: "))
for x in range(height):
for y in range(height):
print("#",end = '')
print()
Upvotes: 3
Views: 1211
Reputation: 1112
height = 6
for rowIndex in xrange(height-1):
row = [' ']*height # yields array of size height
row[0] = row[rowIndex+1] = '#'
print (''.join(row)) # This makes string from array
print ('#'*height) # Print lower side of triangle
You can also remove "+1" on line 5 to get more "edgy" triangles.
Upvotes: 0
Reputation: 106
Here's my solution, it involves the use an of accumulator:
height = int(input("Height of triangle: "))
count = 0
for i in range(height-1):
print('#' + ' '*count + '#')
count += 1
print('#'*height)
Upvotes: 2