Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 旋转矩阵环的第一行出现错误_Python_Python 3.x_Matrix - Fatal编程技术网

Python 旋转矩阵环的第一行出现错误

Python 旋转矩阵环的第一行出现错误,python,python-3.x,matrix,Python,Python 3.x,Matrix,在这段代码中,我得到了下面的错误 Enter M: Traceback (most recent call last): File "main.py", line 1, in <module> M = int(input("Enter M: ")) ValueError: invalid literal for int() with base 10: '4 4' 请帮助我找到python专家。输入数据的代码(问题的输入部分):

在这段代码中,我得到了下面的错误

Enter M: 
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    M = int(input("Enter M: "))
ValueError: invalid literal for int() with base 10: '4 4'
请帮助我找到python专家。

输入数据的代码(问题的输入部分):

输出


如果我理解正确,请任何人帮助我,您试图通过空格一次输入两个数字,而不是通过enter一次输入一个。要用一个输入输入两个数字,您可以这样做:
M,N=[int(x)for x in Input(输入M N:).split(“”)]
Sir问题未解决Sir请帮帮我,Sir请帮帮我,Sir
M = int(input("Enter M: "))
N = int(input("Enter N: "))
 
A = [[0]*N for x in range(M)]
for i in range(0, M):
    for j in range(0, N):
        A[i][j] = int(input())
 
K = int(input("Enter K: "))
Ring = (min(M, N) + 1) // 2
 
count = 0
r = 0
d = 0
l = 0
u = 0
 
for i in range(Ring):
    size = 2*(M-2*i) + 2*(N-2*i) - 4
    if M-2*i == 1:
        size = N-2*i
    if N-2*i == 1:
        size = M-2*i
    if size == 0:
        size = 1
    if size <= K:
        continue
    B = [0] * size
    startX = i
    startY = i
    for r in range(i, N-i):
        B[count] = A[startX][r]
        count += 1
    for d in range(startY + 1, M-i):
        B[count] = A[d][r]
        count += 1
    l = r - 1
    if M-(2*i) > 1 and N-(2*i) > 1:
        while l >= i:
            B[count] = A[d][l]
            count += 1
            l -= 1
        u = d - 1
        while u >= i + 1:
            B[count] = A[u][l+1]
            count += 1
            u -= 1
    for t in range(K):
        temp = B[size - 1]
        j = size - 1
        while j != 0:
            B[j] = B[j-1]
            j -= 1
        B[0] = temp
    
    count = 0
    r = 0
    d = 0
    l = 0
    u = 0
 
    for r in range(i, N-i):
        A[startX][r] = B[count]
        count += 1
    for d in range(startY + 1, M-i):
        A[d][r] = B[count]
        count += 1
    l = r - 1
    if M-(2*i) > 1 and N-(2*i) > 1:
        while l >= i:
            A[d][l] = B[count]
            count += 1
            l -= 1
        u = d - 1
        while u >= i + 1:
            A[u][l+1] = B[count]
            count += 1
            u -= 1
    
    count = 0
    r = 0
    d = 0
    l = 0
    u = 0
 
print("")
for i in range(M):
    for j in range(N):
        print(A[i][j], end = "\t")
    print("")
Test case 1
Input
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
Output
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Test case 2
Input
3 4
1 2 3 4
10 11 12 5
9 8 7 6
2
Output
9 10 1 2
8 11 12 3
7 6 5 4
M, N = [int(x) for x in input("Enter M N: ").split(' ')]
nums = []
for i in range(0, M):
    nums.append([int(x) for x in input(f"Enter {i} row with {N} space-separated integers: ").split(' ')])
K = input("Enter integer K: ")

print(f"You entered:\nM={M},N={N}")
print(f"Lists of entered space-separated integers is:\n{nums}")
print(f"K={K}")
Enter M N: 3 3
Enter 0 row with 3 space-separated integers: 1 2 3
Enter 1 row with 3 space-separated integers: 4 5 6
Enter 2 row with 3 space-separated integers: 7 8 9
Enter integer K: 10
You entered:
M=3,N=3
Lists of entered space-separated integers is:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
K=10