05.用python寫各種三角形
阿新 • • 發佈:2019-01-12
#1.畫等(腰)邊三角形(實心、空心)
#實心:
n=9
for i in range(n):
for j in range(i):
print(' ',end='')
for k in range(i,n):
print('$ ',end='')
print()
#空心 n=9 print('$ '*n) for i in range(1,n-1): for j in range(i): print(' ',end='') print('$ ',end='') for k in range(i,n-2): print(' ',end='') print('$ ',end='') print() print(' '*(n-1)+'$ ') #2.畫倒等邊三角形 #實心 n=9 for i in range(n): for j in range(i): print(' ',end='') for k in range(i,n): print('$ ',end='') print() #空心 n=9 print('$ '*n) for i in range(1,n-1): for j in range(i): print(' ',end='') print('$ ',end='') for k in range(i,n-2): print(' ',end='') print('$ ',end='') print() print(' '*(n-1)+'$ ')