Created
November 9, 2020 18:47
-
-
Save sshehrozali/7c714fd73763f35fcdaa9223c521a39f to your computer and use it in GitHub Desktop.
Python code to print Left & Right aligned Pyramid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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