Skip to content

Instantly share code, notes, and snippets.

@sshehrozali
Created November 9, 2020 18:47
Show Gist options
  • Save sshehrozali/7c714fd73763f35fcdaa9223c521a39f to your computer and use it in GitHub Desktop.
Save sshehrozali/7c714fd73763f35fcdaa9223c521a39f to your computer and use it in GitHub Desktop.
Python code to print Left & Right aligned Pyramid
# Developed By Syed Shehroz Ali #
# Ask user for height of pyramid
height = input("Enter Height of Pyramid: ")
# -------------------------------------
# Start printing Left-aligned pyramid
print("\n----------------")
print("Left pyramid")
print("----------------")
# Print each row
for i in range(int(height) + 1):
# Print each coloumn
for j in range(i):
print("#", end="")
# Print new-line
print("")
# Print new-line
print("\n")
# -------------------------------------
# Start printing Right-aligned pyramid
print("\n----------------")
print("Right pyramid")
print("----------------")
# Print each row
for i in range(int(height) + 1):
# Print spaces
for j in range(int(height) + 1 - i):
print(" ", end="")
# Print each coloumns
for k in range(i):
print("#", end="")
# Print new-line
print("")
# Exit the program
print("Finished")
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment