因此,我尝试在不使用反向函数的情况下从 .txt 文件反转数组。这就是我所拥有的。
numbers = read() #creates numbers array out of the txt file
numbersrev = numbers #blank array for reverse
numLength = len(numbers) #measures the length of the array
print(numbers)
print("Array length of numbers: ", numLength)
i = numLength
i = i-1 #since the array starts at 0 instead of 1
k = 0
for k in range(8):
numbersrev[k] = numbers[i]
print ("The ", i," element of numbers is the ", k," element of numbersrev")
i -= 1
k += 1
print(numbersrev)
这是我在vscode上调试后得到的结果:
[2, 4, 9, 11, 8, 3, 2, 5, 10]
Array length of numbers: 9
The 8 element of numbers is the 0 element of numbersrev
The 7 element of numbers is the 1 element of numbersrev
The 6 element of numbers is the 2 element of numbersrev
The 5 element of numbers is the 3 element of numbersrev
The 4 element of numbers is the 4 element of numbersrev
The 3 element of numbers is the 5 element of numbersrev
The 2 element of numbers is the 6 element of numbersrev
The 1 element of numbers is the 7 element of numbersrev
[10, 5, 2, 3, 8, 3, 2, 5, 10]
顶部数组是原始数组,底部数组是假定的反转数组
我一生都无法找出为什么它在中途停止改变numbersrev数组。有人知道可能是什么原因吗?
守候你守候我
慕标琳琳
慕斯709654
摇曳的蔷薇
相关分类