Intellipaat Back

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

I've composed a program in C++ that shows a pyramid of an asterisk (see underneath) and now I'd prefer to perceive how it's done in Python yet it's not as simple as I'd suspected it would be. 

Has anybody attempted this and if so could you show me code that could assist? 

Thanks in advance :)

       *

      ***

     *****

    *******

   *********

  ***********

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

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

1 Answer

0 votes
by (26.4k points)

Try the below code:

def pyramid(rows=8):

    for i in range(rows):

        print ' '*(rows-i-1) + '*'*(2*i+1)

pyramid(8)

       *

      ***

     *****

    *******

   *********

  ***********

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

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

pyramid(12)

           *

          ***

         *****

        *******

       *********

      ***********

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

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

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

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

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

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

Are you pretty much interested to learn python in detail? Come and join the python training course to gain more knowledge.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 21, 2020 in SQL by Appu (6.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...