Code for printing star pattern using while in python
Answers
Answered by
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:
- Here function takes a number as input
- Then there are two for loops, outer loop is responsible for number of rows,n is given in above code.
- 2nd For loop is responsible to handle the number of columns.
- Value of inner loop(2nd for loop) will vary according to the outer loop.
- After we are printing the star on using print command.
- Then we are ending the line so that it will print in next line(in next iteration of loop).
Similar questions