lundi 17 septembre 2018

Python: For loop pattern

print("Enter the width")
a=int(input())
count=0
for i in range(1,a+1):
    print("*"*i)
    if i==5:
       count=1
    if count==1:
       i-=2

I want a pattern like this

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

when user inputs 5 as the width. But the output I am getting is just

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

What am i doing wrong?

Aucun commentaire:

Enregistrer un commentaire