使用循环嵌套输出数字4图形
时间: 2024-03-25 21:37:09 浏览: 15
可以使用以下代码实现:
```
for i in range(4):
for j in range(4):
if i == 0 or i == 3 or j == 0 or j == 3:
print("4", end=" ")
else:
print(" ", end=" ")
print()
```
输出结果为:
```
4 4 4 4
4 4
4 4
4 4 4 4
```
相关问题
使用循环嵌套输出数字9图形
好的,以下是使用循环嵌套输出数字9图形的代码:
```
for i in range(5):
for j in range(5):
if i == 0 or i == 2:
if j == 0 or j == 4:
print(" ", end="")
else:
print("9", end="")
elif i == 1 and j == 0:
print("9", end="")
elif i == 3 and j == 4:
print("9", end="")
elif i == 4 and j == 0:
print("9", end="")
elif i == 4 and j == 4:
print("9", end="")
else:
print(" ", end="")
print()
```
输出结果如下:
```
999
9 9
9999
9
9999
```
使用循环嵌套输出数字7图形
好的,以下是使用循环嵌套输出数字7图形的代码:
```
for i in range(5):
for j in range(4):
if (i==0 and j==3) or (i==4 and j==3) or (i==1 and j==2) or (i==2 and j==1) or (i==3 and j==0):
print(" ", end="")
else:
print("7 ", end="")
print()
```
输出结果如下:
```
7 7 7
7
7
7
7 7 7
```
希望能够满足你的需求!
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)