Home > Back-end >  I keep getting this error on python on codeacademy
I keep getting this error on python on codeacademy

Time:10-10

I keep getting the error:

line 16, in <module> gradebook.remove[2](85)
type error: 'built_in_function_or_method' object is not subscriptable.

I don't know what I am doing wrong... can anyone please help me. My code is as below:

last_semester_gradebook = [["politics", 80], ["latin", 96], ["dance", 97], ["architecture", 65]]

# Your code below: 
subjects = ["physics", "calculus", "poetry", "history"] #grades grades = [98, 97, 85, 88]

gradebook = [["physics", 98], ["calculus", 97], ["poetry", 85], ["history", 88]] print(gradebook) gradebook.append(["computer science", 100]) gradebook.append(["visual arts", 93]) print(gradebook)

gradebook[-1][-1] = 98

gradebook.remove2

gradebook.append4

full_gradebook = last_semester_gradebook   gradebook

print(full_gradebook)

CodePudding user response:

gradebook.remove[2]

does not remove the third item from the list.

gradebook.pop(2)

will remove the third item

CodePudding user response:

Correct syntax of the remove() and append() methods:

List_name.remove(item)
List_name.append(item)

It means you have to use items inside the parentheses. So your code needs to be like this

last_semester_gradebook = [["politics", 80], ["latin", 96], ["dance", 97], ["architecture", 65]]

# Your code below: 
subjects = ["physics", "calculus", "poetry", "history"] #grades 
grades = [98, 97, 85, 88]
gradebook = [["physics", 98], ["calculus", 97], ["poetry", 85], ["history", 88]]
print(gradebook) 

gradebook.append(["computer science", 100]) 
gradebook.append(["visual arts", 93])
print(gradebook)

gradebook[-1][-1] = 98
gradebook.remove(gradebook[2])
gradebook.append(gradebook[4])
full_gradebook = last_semester_gradebook   gradebook
print(full_gradebook)
  • Related