Gettin AttributeError:

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

subjects = [‘physics’, ‘calculus’, ‘poetry’, ‘history’]
grades = [98, 97, 85, 88]

gradebook = [subjects[0], grades[0]], [subjects[1], grades[1]], [subjects [2], grades[2]], [subjects [3], grades [3]]

print(gradebook)

gradebook.append([“computer science”, 100])

print(gradebook)

Traceback (most recent call last):
File “script.py”, line 12, in
gradebook.append([“computer science”, 100])
AttributeError: ‘tuple’ object has no attribute ‘append’

Because of the missing opening bracket, Python is treating this sequence as a tuple, hence the error. Add the front bracket and the list will be in order.

1 Like