Does anyone know how to save a string with multiple prints in for function? I am able to draw a pyramid, but I am stuck on writing it to a file.
Here is my code:
n = int(input("Enter number: "))
file_1 = open("pyramid.txt", "a")
for i in range(1, n + 1):
for j in range(1, n - i + 1):
file_1.write(" ", end="")
for j in range(1, i + 1):
file_1.write("* ", end="")
print("")
file_1.close()