# Triangle Tessellation Help

``````height = int(input())
columns = int(input())
rows = int(input())
for a in range(height):
for b in range(a, height):
print(" ", end="")
for b in range(a):
print("*", end="")
for b in range(a+1):
print("*", end="")
print()
``````

This is my code, when I run said code, it prints a triangle with an extra space. My code can print triangles in columns but cannot print them side by side. I have tried many things to get rid of the extra space and print them side by side, but nothing has worked. Can someone help?

The only way to print triangles side by side is to interleave them, computing the positions of points on the same printed line. That means creating a data set composed of all the triangles, then iterating over the data to draw all the figures in one go.

For an example of what I mean, DM me for the URL to my Block Letters repl (donâ€™t want to self-promote). Please include a link to this topic so I can make the connection.

1 Like

You got one loop that makes the spaces - so all you gotta do is reduce the range for the loop by one.

``````height = int(input())
columns = int(input())
rows = int(input())
for c in range(columns):
for a in range(height):
for b in range(a, height-1):
print(" ", end="")
for b in range(a):
print("*", end="")
for b in range(a+1):
print("*", end="")
print()
``````

I would like some help with my triangle tessellation code, I have figured out how to print multiple triangles on top of each other(the rows) and how to make 1 star pattern triangle. However, i am having extreme difficulty printing the triangle side by side, is there anyone who can help?

Well plain Python doesnâ€™t print side-by-side, it only prints lines. So if you want triangles side-by-side, you still have to construct the result line-by-line.

There are some way to do this, though you definitly need a more complex logic.
Obviously a more advanced way would be to create some â€śgridâ€ť with coordinates to which you can add triangles based on the position of points. After all, thatâ€™s how itâ€™s usually done on a screen - creating the representation of it in data and then reading and projecting that data line-by-line.

For this youâ€™d need some code-object representing the grid. For a start, nested lists could do the trick.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.