05.用python写各种三角形

05.用python写各种三角形_第1张图片

#1.画等(腰)边三角形(实心、空心)
 #实心:
n=9
for i in range(n):
    for j in range(i):
        print(' ',end='')
    for k in range(i,n):
        print('$ ',end='')
    print()

05.用python写各种三角形_第2张图片

#空心
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)+'$ ')

你可能感兴趣的:(python学习)