用python输入数字打印图形 样例输入:5 样例输出: ***** * * * * * * *****
时间: 2023-08-29 15:05:30 浏览: 83
Python中输入和输出(打印)数据实例方法
下面是一个简单的实现,可以打印出指定大小的矩形:
```python
n = int(input())
for i in range(n):
for j in range(n):
if i == 0 or i == n-1 or j == 0 or j == n-1:
print("*", end="")
else:
print(" ", end="")
print()
```
如果要打印出上述的样例输出,可以稍微修改一下:
```python
n = 5
for i in range(n):
for j in range(n):
if i == 0 or i == n-1 or j == 0 or j == n-1:
print("*", end="")
else:
print(" ", end="")
print()
```
输出:
```
*****
* *
* *
* *
*****
```
阅读全文