如何使用Python 打印各种三角形

时间:2021-08-05 12:13:44

直角三角形

?
1
2
3
4
5
6
7
rows = int(input('输入列数:'))
for i in range(1, rows):
print('*' * i)
for i in range(1, rows):
for j in range(i):
print("*", end="")
print("")

等腰直角三角形

?
1
2
3
4
5
6
7
rows = int(input('输入列数:'))
for i in range(1, rows):
print(' * ' * i)
for i in range(1, rows):
for j in range(1, i + 1):
print(" * ", end="")
print("")

打印等腰三角形

?
1
2
3
4
5
rows = int(input('输入列数:'))
for i in range(1, rows):
if i % 2 != 0:
str = ('*' * i)
print(str.center(9, ' '))

正方形1

?
1
2
3
4
5
6
7
rows = int(input('输入列数:'))
for i in range(0, rows):
print(" * " * rows)
for i in range(0, rows):
for j in range(0, rows):
print(" * ", end="")
print(" ")

正方形2

?
1
2
3
4
5
6
7
8
9
10
11
print('正方形2')
for i in range(10):
for j in range(0, 10 - i):
print(end=' ')
for n in range(0, 0 + i):
print(end=' ')
for m in range(0 + i, 10):
print('', end=' ')
for k in range(10 - i, 10):
print('', end=' ')
print('')

打印倒立直角三角形

?
1
2
3
4
for x in range(10):
for i in range(x, 10):
print('*', end='')
print('')

同一行打印直角三角形

?
1
2
3
4
5
6
7
8
9
print('同一行打印直角三角形')
for j in range(10):
for x in range(0, j):
print('', end='')
for n in range(j, 19 - j):
print(' ', end='')
for k in range(0, j):
print('', end='')
print('')

直角三角形拼装心形

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
print('直角三角形拼装心形')
for j in range(8):
for x in range(0, j):
print('', end='')
for n in range(j, 19 - j):
print(' ', end='')
for k in range(0, j):
print('', end='')
print('')
for i in range(10):
for j in range(0, 0 + i):
print(end=' ')
for k in range(0 + i, 10):
print('*', end=' ')
print('')

打印倒立等腰三角形1

?
1
2
3
4
5
6
print('打印倒立等腰三角形1')
for j in range(10):
for x in range(0, j):
print(end=' ')
for n in range(j, 15 - j):
print('*', end='')

打印倒立等腰三角形2

?
1
2
3
4
5
6
7
print('打印倒立等腰三角形2')
for i in range(10):
for j in range(0, 0 + i):
print(end=' ')
for k in range(0 + i, 10):
print('*', end=' ')
print('')

同一行打印两个等腰三角形

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
print('同一行打印两个等腰三角形')
for i in range(10):
for j in range(0, 10 - i):
print(end=' ')
for k in range(10 - i, 10):
print('', end=' ')
for n in range(0, 0):
print(end=' ')
for m in range(0 + i, 10):
print(' ', end=' ')
for jj in range(10, 10):
print(end=' ')
for kk in range(10 - i, 10):
print('', end=' ')
print('')

等腰三角形拼装心形

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
print('等腰三角形拼装心形')
for i in range(10):
for j in range(0, 10 - i):
print(end=' ')
for k in range(10 - i, 10):
print('', end=' ')
for n in range(0, 0):
print(end=' ')
for m in range(0 + i, 10):
print(' ', end=' ')
for jj in range(10, 10):
print(end=' ')
for kk in range(10 - i, 10):
print('', end=' ')
print('')
for i in range(20):
for j in range(0, 0 + i):
print(end=' ')
for k in range(0 + i, 20):
print('*', end=' ')
print('')

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.jianshu.com/p/bac24339087e