思維練習-13: 列印一個對頂三角形
阿新 • • 發佈:2018-12-09
while True:
height = int(input('請輸入三角形的高:'))
starNumber1 = height * 2 - 1
print(starNumber1 * '*')
spaceNumber = 0
starNumber = 1
for line in range(2,height*2):
if line < (height + 1):
spaceNumber = spaceNumber +1
starNumber = (starNumber1 - spaceNumber*2 )
print(spaceNumber*' ' + starNumber*'*' + spaceNumber*' ')
else:
starNumber = starNumber +2
spaceNumber = int((starNumber1 - starNumber) / 2)
print(spaceNumber * ' ' + starNumber * '*' + spaceNumber * ' ')