Python array.append错误,我该如何解决?

时间:2017-06-25 13:52:41

标签: python arrays python-3.x

我正在尝试制作笔记本2D阵列但是当我尝试运行该程序时,我收到语法错误,突出显示array中的array.append([ask](note))。 请帮我解决这个问题。谢谢!

for i in range (0,9):
array = [["Section 0",],["Section 1",],["Section 2",],["Section 3",],["Section 4",],["Section 5",],["Section 6",],["Section 7",],["Section 8",],["Section 9",]]
print(array)
ask = int(input("What section of the book do you want to change or add the note? 0-9 :"))
if ask <= 9:
    print("Can you not read?")
    input()
else:
    note = str(input("What note do you want in your chosen section? : ")
    array.append([ask](note))
    print(array)

input()

1 个答案:

答案 0 :(得分:2)

正确的语法是array[ask].append(note)

此外,即使他们输入了有效的区号,您也会侮辱用户。

for i in range (0, 9):   
    array = [["Section 0",],["Section 1",],["Section 2",],["Section 3",],["Section 4",],["Section 5",],["Section 6",],["Section 7",],["Section 8",],["Section 9",]]
    print(array)
    ask = int(input("What section of the book do you want to change or add the note? 0-9 :"))
    if not 0 <= ask <= 9:
        print("Can you not read?")
        input()
    else:
        note = str(input("What note do you want in your chosen section? : "))
        array[ask].append(note)
        print(array)