Below is a code I made in Python for our lab activity which makes a triangle.
side = input("Input side: ")
def triangle(x):
print ((x - 1)*" "),"*"
asterisk = "*"
space = side
for i in range(x):
asterisk = "**" + asterisk
space = (space-1) * " "
print space,asterisk
triangle(side)
The output should be this:
*
***
*****
I got the number of asterisks on each row correctly, but I cannot figure out how to make the necessary amount of spaces to make it look like a triangle. Using the above code, which I think might be the solution, always produces an error at line 9. Any help I appreciated. (I'm new here so if I violated some rules please let me know.) Thanks and good day!