Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k points)

How would I print out a number triangle in python utilizing a loop-based program? It's anything but a schoolwork assignment or anything it's simply an activity from the book I have been attempting to do yet have not actually approached. The triangle should print out resembling this:

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

6 6 6 6 6 6

1 Answer

0 votes
by (26.4k points)

Kindly check the below code:

for i in range(7):

    print (str(i) + " ")*i

Output:

1  

2 2  

3 3 3  

4 4 4 4  

5 5 5 5 5  

6 6 6 6 6 6  

Are you looking for a good python tutorial? Join the python course fast and gain more knowledge in python.

Watch this video tutorial for more information.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 23, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 8, 2019 in Python by Sammy (47.6k points)

Browse Categories

...