i+=1
for i in range(n):
flag=True
for j in range(n):
if flag:
print(arr[i][j],end=“”)
flag=False
else:
print(“\t”,arr[i][j],end=“”,sep=“”)
print()
def sn2(n):
arr=[]
for i in range(n):
arr.append([0]*n)
row=0
col=n-1
arr[row][col]=i=1
while i<n*n:
while(col-1>-1 and not(arr[row][col-1])):
arr[row][col-1]=i+1
i+=1
col-=1
while(row+1<n and not(arr[row+1][col])):
arr[row+1][col]=i+1
i+=1
row+=1
while(col+1<n and not(arr[row][col+1])):
arr[row][col+1]=i+1
i+=1
col+=1
while(row-1>-1 and not(arr[row-1][col])):
arr[row-1][col]=i+1
i+=1
row-=1
for i in range(n):
flag=True
for j in range(n):
if flag:
print(arr[i][j],end=“”)
flag=False
else:
print(“\t”,arr[i][j],end=“”,sep=“”)
print()
if name==“main”:
n=int(input())
print(“蛇形数组如下(顺时针):”)
sn1(n)
print(“蛇形数组如下(逆时针):”)
sn2(n)
‘’’
大家都学习过矩阵,今天呢咱们将n*n类型的字符矩阵进行向左的90°旋转
‘’’
#生成全为零的矩阵
arr=[]
n=int(input())
for i in range(n):
arr.append([0]*n)
#蛇形矩阵
row=0
col=n-1
arr[row][col]=i=1
while i<n*n:
while row+1<n and not arr[row+1][col]:
arr[row+1][col]=i+1
i+=1
row+=1
while col-1>=0 and not arr[row][col-1]:
arr[row][col-1]=i+1
i+=1
col-=1
while row-1>=0 and not arr[row-1][col]:
arr[row-1][col]=i+1
i+=1
row-=1
while col+1<n and not arr[row][col+1]:
arr[row][col+1]=i+1
i+=1
col+=1
print(“旋转前如下:”)
for temp in arr:
print(temp)
print()
print(“旋转后如下(旋转90°):”)
for i in range(4):
flag=True
for j in range(4):
if flag:
print(arr[j][3-i],end=“”)
flag=False
else:
print(" “,arr[j][3-i],end=”")
最后
不知道你们用的什么环境,我一般都是用的Python3.6环境和pycharm解释器,没有软件,或者没有资料,没人解答问题,都可以免费领取(包括今天的代码),过几天我还会做个视频教程出来,有需要也可以领取~
给大家准备的学习资料包括但不限于:
Python 环境、pycharm编辑器/永久激活/翻译插件
python 零基础视频教程
Python 界面开发实战教程
Python 爬虫实战教程
Python 数据分析实战教程
python 游戏开发实战教程
Python 电子书100本
Python 学习路线规划
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!