1.直角三角形
a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(i):
print(end='*')
print()
2.等腰三角形
a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(a+1-i):
print(end=' ')
for k in range(2*i-1):
print(end='*')
print()
3.倒三角形
a = int(input('請輸入打印行數:'))
for i in range(a):
for j in range(i):
print(end=' ')
for k in range(2*(a-i)-1):
print(end='*')
print()
4.菱形
a = int(input('請輸入打印行數:'))
for i in range(1,a//2+1):
for k in range(a//2+1-i):
print(end=' ')
for j in range(2*i-1):
print('*',end='')
print()
for i in range(a//2+1):
for k in range(i):
print(end=' ')
for j in range(a-2*i):
print('*',end='')
print()
5.平行四邊形
a = int(input('請輸入打印行數:'))
for i in range(a):
for j in range(a-i):
print(end=' ')
for k in range(a):
print(end='*')
print()
6.空心菱形
a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(a+1-i):
print(end=' ')
for k in range(2*i-1):
if i == 1 or k == 0 or k== 2*i-2:
print(end='*')
else:
print(end=' ')
print()
for i in range(1,a+1):
for j in range(i):
print(end=' ')
for k in range(2*(a-i)):
if k == 1 or k== 2*(a-i)-1:
print(end='*')
else:
print(end=' ')
print()
7.十字菱形
a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(a+1-i):
print(end=' ')
for k in range(2*i-1):
if i == 1 or k == 0 or k== 2*i-2 or i ==a or k ==i-1:
print(end='*')
else:
print(end=' ')
print()
for i in range(1,a+1):
for j in range(i):
print(end=' ')
for k in range(2*(a-i)):
if k == 1 or k== 2*(a-i)-1 or k == a-i:
print(end='*')
else:
print(end=' ')
print()