Hi, in this article you will learn a Python program to print right angle triangle with n rows and n columns. Let's ask the user to enter the value of n using the input function call and then print the right angle triangle.
I will be solving this using 3 lines of code.
Take an Input n as an Integer And Write a Program to Display a Right Angle Triangle With n Rows And n Columns in Python
Let's take a variable name as n and ask the user to enter the number using the input function call and then convert it into an integer.
n = int(input("Enter a Number : "))
Take a for loop and iterate from 0 to n and get the column variable as shown below, use the print statement to print the star and space multiplied by the column + 1. Once you keep printing the star and space multiply by column index it will print a perfect right angle triangle.
for column in range(n):
print("* " * (column + 1))
Complete Python Program
===============================
n = int(input("Enter a Number : "))
for column in range(n):
print("* " * (column + 1))
Output 1
======================
Enter a Number : 4
*
* *
* * *
* * * *
Output 2
======================
Enter a Number : 12
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
Conclusion
================
Execute the above Python program by providing the random integer as a input to it and note down the results.
Comment it down below if you have any queries regarding the above Python program
0 Comments