#中空等腰斜線三角形
def triangle(num):
count = num
for n in range(0,num,1):
if n+1 == num:
print(' '+ '/'+'_'* (2*(num-1)) +'\\')
elif n == 0:
print((' '*(count))+'/\\')
count -= 1
else:
print((' '*(count))+'/'+(' '*(2*(n))+'\\'))
count -= 1
triangle(5)
# /\
# / \
# / \
# / \
# /________\
等腰斜線三角形(tree)
def triangle0(num):
count = num
for n in range(0,num,1):
#0,1,2
if n+1 == num:
print(' '+ '/'+'_'* (2*(num-1)) +'\\')
elif n == 0:
print((' '*(count))+'/\\')
count -= 1
else:
print((' '*(count))+'/'+('^'*(2*(n))+'\\'))
count -= 1
triangle0(5)
# /\
# /^^\
# /^^^^\
# /^^^^^^\
# /________\
Asterisk 星號
中空等腰三角形
#中空等腰三角形
def triangle1(num):
star = 1
for i in range(num):
if i == 0 or i == num-1:
star_ = format("*"*star,"^"+str(num*2-1))
else:
star_ = format("*"+" "*(star-2)+"*","^"+str(num*2-1))
star += 2
print(star_)
triangle1(5)
# *
# * *
# * *
# * *
# *********
實心等腰三角形
#實心等腰三角形
def pyramid(n):
for i in range(n+1):
print(' '*(n-i)+'*'*(2*i-1))
pyramid(5)
# *
# ***
# *****
# *******
# *********