-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinverted_pyramid.py
More file actions
44 lines (28 loc) · 949 Bytes
/
Copy pathinverted_pyramid.py
File metadata and controls
44 lines (28 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
lets write a program which will print a inverted pyramid of stars.
*****
***
*
like this
logic:
loop 1 : iterate through rows
loop 2 : print spaces form 1 to i-1 th index
loop 3 : print srats from 1 to 2*n-(2*i-1)th index
'''
n = int(input("enter the number of rows: "))
#iterate through rows
for i in range(1,n+1):
for j in range(1,i):
#print space from 1 to i-1 index
print(" ", sep=" ", end=" ")
for k in range(1, 2*n-(2*i-1)+1):
#print stars from 1 to 2*n-(2*i-1) th index/column
print("*", sep=" ", end=" ")
print() #for printing new line
'''
if n= 3
then in 1st iteration print 0 space and 2*3-(2*1-1)= 5 stars
2nd iteration print 1 to 2(i) = 1 space and 2*3-(2*2-1)= 3 stars
3rd iteration print 1 to 3(i) = 2 space and 2*3-(2*3-1)= 1 stars
hope you got the logic thanks
'''