Python: How to Write Logic to Print Triangle

Here's an example to print Triangle in Python. It's the best interview question. You can expect this type of question in your interview. So this is useful to practice it.

How to print triangle in python



How to Print Triangle


Logic to Print Trianagle


max = 8
 for x in range(1, max + 1):
     for y in range(1, x + 1):
         print y,
         print 

Result


1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

 Also, Read

Post a Comment

Thanks for your message. We will get back you.

Previous Post Next Post