用Python编程输出以下图形 (1) * ** *** **** ***** **** *** ** * (2) 
时间: 2023-11-25 11:49:49 浏览: 76
人工智能A*算法实现+python+北邮人工智能实训作业
5星 · 资源好评率100%
以下是两种Python编程输出图形的例子:
(1)
```python
num = int(input("请输入要生成的行数N:"))
i = 1 # 行数
while i <= num:
if i <= num - i: # 增
k = i # 每行生成的个数
while k > 0:
print("*",end='')
k-=1
print("\n")
else: # 减
k = num - i + 1 # 生成的个数
while k > 0:
print("*",end='')
k-=1
print("\n")
i+=1
```
(2)
```python
for i in range(1, 6):
for j in range(i):
print("*", end="")
print()
for i in range(4, 0, -1):
for j in range(i):
print("*", end="")
print()
```
阅读全文