As a newbie programmer

Using loops to draw patterns(Pyramid) @ Dcoder

Dcoder icon

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

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?