In this Python program, you will learn to print the right angled triangle of the same character or alphabet in each and every row and column using for loop, while loop, and functions.
The below example accepts the user-entered rows, and the nested for loop iterates the rows and columns. Next, the program will print the right angled triangle of the same character or alphabet (A).
rows = int(input("Enter Rows = "))
a = 65
for i in range(rows):
for j in range(i + 1):
print('%c' %a, end= ' ')
print()
Enter Rows = 9
A
A A
A A A
A A A A
A A A A A
A A A A A A
A A A A A A A
A A A A A A A A
A A A A A A A A A
Instead of a For loop, this program uses the while loop to iterate the rows and columns and prints the right angled triangle of the same character at each position.
rows = int(input("Enter Rows = "))
a = 65
i = 0
while i < rows:
j = 0
while j < i + 1:
print('%c' %a, end= ' ')
j += 1
i += 1
print()
Enter Rows = 11
A
A A
A A A
A A A A
A A A A A
A A A A A A
A A A A A A A
A A A A A A A A
A A A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A
This Python program allows the user to enter the rows and the alphabet characters. Next, the rightTriangleSameChar function uses nested for loops to print the right angled triangle of a given character on rows and columns.
def rightTriangleSameChar(rows, a):
for i in range(rows):
for j in range(i + 1):
print('%c' %a, end=' ')
print()
rows = int(input("Enter Rows = "))
a = input("Enter Character = ")
rightTriangleSameChar(rows, a)