If n=4
Output
A
AB
BCC
CDDD
If n=5
Output
A
AB
BCC
CDDD
DEEEE
def print_pyramid(N):
# Iterate over each row from 1 to N
for i in range(N):
# Calculate the starting character for each row
start_char = chr(ord('A') + i)
# Calculate the number of times to repeat the starting character
repeat_count = i + 1
# Generate the current row
row = ''.join([chr(ord(start_char) + j) for j in range(repeat_count)])
# Print the current row
print(row)
Example usage:
N = 4
print_pyramid(N)
New contributor
Reverse gear is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.