用Python5、编程输出以下图形 (1) * ** *** **** ***** **** *** ** * (2)
时间: 2023-11-25 13:49:16 浏览: 52
使用Python绘制图形详解二
5星 · 资源好评率100%
(1) 代码如下:
```python
layer = 5
for i in range(1, 2*layer):
if i <= layer:
for j in range(i):
print("*", end="")
else:
for j in range(2*layer-i):
print("*", end="")
print("")
```
(2) 代码如下:
```python
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1, 1, 500)
y1 = np.sqrt(1 - np.power(np.abs(x) - 1, 2))
y2 = -3 * np.sqrt(1 - np.power(np.abs(x) / 2, 0.5))
fig, ax = plt.subplots()
ax.fill_between(x, y1, color="red")
ax.fill_between(x, y2, color="red")
plt.axis("off")
plt.show()
```
阅读全文