Computer Science, asked by Sidiscool198, 1 year ago

Code for printing star pattern using while in python

Answers

Answered by rajgraveiens
1

Answer:

#Below is function to print pyramid of stars

def star_pattern(n):        

   for row in range(0, n):  

       for column in range(0, row+1):  

           print("* ",end="")  

       print("\r")  

n = int(input("Please Enter a Number to from a pyramid of n line : "))

star_pattern(n)

Explanation:

Description of above code to print pyramid of stars is given below:  

  1. Here function takes a number as input
  2. Then there are two for loops, outer loop is responsible for number of rows,n is given in above code.
  3. 2nd For loop is responsible to handle the number of columns.
  4. Value of inner loop(2nd for loop) will vary according to the outer loop.
  5. After we are printing the star on using print command.
  6. Then we are ending the line so that it will print in next line(in next iteration of loop).

Similar questions