Python Competitive Programming Questions |
In this article, we are going to write Python code to print out the right-angled shape triangle.
If you are looking for a python tutorial then it's here
We can solve this problem using 2 methods. If you are willing to solve the problem using Python then you can do this using the following way:
def RightTriangle(rows):
for i in range(1, rows+1):
print('*'*i)
def main():
RowInput = int(input('Enter the number of rows: '))
RightTriangle(RowInput)
main()
The output is:
Enter the number of rows: 10
*
**
***
****
*****
******
*******
********
*********
**********
If you want to do it in a simple way. Then it's just a 3 lines code problem
rows = int(input('Enter the number of rows: '))
for i in range(1, rows+1):
print('*'*i)
The output is:
Enter the number of rows: 10
*
**
***
****
*****
******
*******
********
*********
**********
Comments
Post a Comment