PY
py
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
"""A triangle , you can consider it half diamond.Till (base*2-1) So if you are making a diamond , you create a base which is
value_entered*2-1. up and down that base would be even number of lines containing stars(characters).
"""
diamond=int(input()) #e.g == input 15
# now to give number of 1 less space than the middle of the index of triangle since we would print our...
#...first star at 15 index since , which is center(because base row would be double-1 of value entered)...
#...since the we r taking input 15 for now.
spaces1=diamond-1 #to determine the base of triangle ,
spaces2=diamond-spaces1
# spaces2=diamond-spaces1 #to determine the spaces(if making another) well thats one but still took variable
for i in range(1,diamond+spaces1+1,2): #e.g i in range(1,15+14+1),step is 2 ,i would be 1,3,5...
print(" "*spaces1+"*"*i) # printing space multipilied * spaces , which would only on left(your) ...
# ...side since computer considers spaces as characters and ,star multiplied to i. so number of stars increasing by two
#and number of spaces decreasing by one. i is increasing so spaces as well and ......
spaces1=spaces1-1 #.....spaces are decreasing by one.
spaces1=diamond-1 #==14 assigning the same value again to create the desired range , now the base is printed , which 29 as input is 15.
for a in range(diamond+spaces1-2,0,-2): # a in range( 15+14-2)==27 , now we print the 27,0 ,2 , so a would decrease by 2.
print(" "*spaces2+"*"*a) # now we will multiply spaces2(which is) into space, and '*' so a is decreasing ,'*' would decrease by two
spaces2=spaces2+1 # spaces2 is increasing , so spaces would increase by 1. as you can see.
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run