Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print the following pattern left sided right angle triangle | Python |

I want to print the below pattern

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

I have a below logic which prints the desired output as expected in above
Is it a right approach to print the pattern. Any other approach / unique trick to get the output

for row in range(1,6):
  for col in range(1,6):
    if row is col:
      print(row * '* ')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You don’t need the second for loop, just print your line directly:

for row in range(1,6):
  print(row * '* ')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading