Print Right-Angled Triangle

Write a Python program that uses a while loop to print a right-angled triangle of height ‘n’, where ‘n’ is an input from the user.

Example 1:

Input: 5

Output:

*
**
***
****
*****

Example 2:

Input: 3 

Output:
*
**
***

Consider how the number of asterisks relates to each row of the triangle. You could use nested loops to solve this problem.

n = int(input(“Enter triangle height: “))
i = 1
while i <= n:
print(‘*’ * i)
i += 1

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!