Dcoder icon

Using loops to draw patterns(Pyramid) @ Dcoder

By Lochard | As a newbie programmer | 8 Jul 2023


Problem: Draw the pattern specified using loops.

Input: 

Output: The pattern as shown in sample output.

First line contain 4 space and 1 star, next line contains 3 space and 3 stars and so on..

Constraints: Try not to hardcode the output.

Sample Input: 

Sample Output: 

    *

   ***

  *****

 *******

*********

for i in range(1, 6):
  print(' '*(5-i) + '*'*(i*2-1))

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.