lundi 7 juin 2021

How to reduce the number of variables used here?

def pat_1(rows):  
    k=0
    for i in range(1,rows+1):
        for j in range(1,(rows-i)+1):
            print(end=" ")
        while(k!=(2*i-1)):
            print("*",end="")
            k+=1
        k=0
        print()
        
n=int(input("Enter the number of rows:"))
pat_1(n)

How to reduce the number of variables in the above code? and also suggest me ways to remove this while loop

Output is something like this: for n=3

    *
   ***
  *****

Aucun commentaire:

Enregistrer un commentaire