Intellipaat Back

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

I am utilizing the accompanying loop code to print the star pattern and the code is turned out completely great. Here is my code

for i in range(1,6):

    for j in range(i):

        print("*", end=" ")

    print()

Output:

* * 

* * * 

* * * * 

* * * * * 

But, How to get this pattern?

         * 

        * * 

       * * * 

      * * * * 

     * * * * * 

1 Answer

0 votes
by (26.4k points)

Look at the below code. Just try to add spaces loop ahead.

for i in range(1,6):

    for j in range(6-i):

        print(" ", end="")

    for j in range(i):

        print("*", end=" ")

    print()

Want to learn python to get expertise in its concepts? Join python certification course and get certified

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 25, 2021 in Java by RohitSingh (2.6k points)
0 votes
1 answer

Browse Categories

...