Python

wondering what this syntax means im stuck with another and if another question if you need more details let me know
Traceback (most recent call last):
File “script.py”, line 13, in
gradebook.append([“Computer Science”,100])
AttributeError: ‘tuple’ object has no attribute ‘append’

Hi,
It means python is treating gradebook as a tuple, not a list.
A tuple is like a list but can’t be altered so append won’t work.
e.g
a_tuple = (“a”, “b”, “c”)

a_list = [“a”, “b”, “c”]

So, you probably want to look back at when you first created gradebook. That’ll be where your issue is.

1 Like

thanks for you help I tried rearranging some things but im still stuck here’s the code with grade book

gradebook=[“physics”,98],[“calculus”,97],[“poetry”,85],[“history”,88]

print(gradebook)

gradebook.append[“Computer Science”,100]

it says the line with computer science is well basically that
Traceback (most recent call last):
File “script.py”, line 12, in
gradebook.append[“Computer_Science”,100]
AttributeError: ‘tuple’ object has no attribute ‘append’

like what you said I tried changing a few things

you are missing a [ at the beginning and a ] at the end to make it a list of lists:

example:

(1, 2, 3) # tuple
1, 2, 3  # tuple, without the ( and ) on the outside
[1, 2, 3]  # list

2-dimensional version:

( (1,2), (3,4), (5,6) )  #// tuple of tuples (2D tuple)
( [1,2], [3,4], [5,6] )  #// tuple of lists
[1,2], [3,4], [5,6]  #// tuple of lists, again
[ [1,2], [3,4], [5,6] ]  #// list of lists (2D list)

I think the last one is what the exercise wants.

You are missing the ( and ) after .append ;
it should be gradebook.append( ["Computer_Science",100] )
because .append is a function.

thanks for your help
this is what I did before gradebook.append([“computer_science”,100] )
and it still comes out to this
Traceback (most recent call last):
File “script.py”, line 12, in
gradebook.append( [“computer_science”,100] )
AttributeError: ‘tuple’ object has no attribute ‘append’

Did you put the [ and ] for gradebook to make it a list of lists?
gradebook = [ ["physics",98], ["calculus",97], ["poetry",85], ["history",88] ]

I think thats what it was I didn’t make it a least im going to continue if I need more help ill ask thanks a lot

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.