Competitive Programming In Python For Beginners |
In this article, we are going to print out the Pyramid Alphabet Pattern in Python.
If you are looking for a Python Tutorial Series then it's here
Before we jump into the code, let's first understand ASCII value and ASCII character
ASCII Characters ASCII Value
A-Z 65-90
a-z 97-122
0-9 48-57
Spceial Symbols 0-47, 58-64, 91-96, 123-127
The Code Part:
def pyramid(num):
asciiValue = 65
for i in range(num):
for j in range(num-i-1):
print(" ", end="")
for k in range(asciiValue, asciiValue+i+1):
print(chr(k), end="")
for l in range(asciiValue, asciiValue+i):
print(chr(l), end="")
print()
pyramid(6)
The output of the code is:
A
ABA
ABCAB
ABCDABC
ABCDEABCD
ABCDEFABCDE
Comments
Post a Comment