Stuck with Gradebook

https://www.codecademy.com/paths/computer-science/tracks/cspath-cs-101/modules/cspath-python-lists/projects/python-gradebook

Please help me with the project - Gradebook.

When I use gradebook=list (zip(subjects, grades)) , it creates a list of tuples that I cannot modify later. How can I create a list of lists here?

Hello! I had some trouble understanding the new version of the project, myself.

The new version wants 2D lists–that is, lists written with brackets within brackets. [["It", "will"], ["look", "something"], ["like", "this"]].

zip is no longer used in this project. You will have to manually type out your own 2D list, after having typed two lists on their own (seems redundant, but…). In the end, it should look like this:

gradebook = [["Physics", 98], ["Calculus", 97], ["Poetry", 85], ["History", 88]]

No more tuples! Except for in their past gradebook, for whatever reason…

Hope this helps! The curriculum revision this week has caused some confusion all around.

3 Likes

More on tuples, which are immutable.

Thank a lot for the prompt reply

Greatly appreciated!

1 Like

Hi @ekaseda

But even if you manually define the 2D list “gradebook” later on in the project you are asked to add a sublist of “Subject and Grade” to your already 2 dimensional list “gradebook” ,

Your grade for visual arts just came in! You got a 93!
Use append to add ["Visual Arts", 93] to gradebook .

and when you use .append it creates a tuple… how can you modify it later after using append?

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

# Your code below: 

subjects = ["Physics", "Calculus", "Poetry", "History"]
#subjects.append("Computer Science")
grades = [98, 97, 85, 88]
#grades.append(100)
gradebook = [('Physics', 98), ('Calculus', 97), ('Poetry', 85), ('History', 88)]

gradebook.append(("Computer Science", 100))
gradebook.append(("Visual Arts", 93))
list_gradebook = list(gradebook)
list_gradebook[-1][1] = 98

print(list_gradebook)

That gives me the same immortal tuple error :frowning:

That’s a list of tuples. A list of lists would look similar to:

[['a', 1], ['b', 2], ['c', 3]]
# each element of the outer list is a list

Using parenthesis instead of square brackets creates tuples which are immutable.

2 Likes

What midlindner said. It looks like you haven’t made a 2D list at all. Your manually-typed 2D list should look like this:

gradebook = [["Physics", 98], ["Calculus", 97], ["Poetry", 85], ["History", 88]]

This is different from the list of tuples in last_semester_gradebook, which seems to be a holdover from before, when they didn’t use append or 2D lists in the project.

Then when you append, you should append the whole list:

gradebook.append([“Visual Arts”, 93])

In your example code, it looks like you’re using tuples (with parentheses) rather than lists (with brackets). Change that, and you shouldn’t get errors. :+1:

3 Likes

OMG! how come i didn’t see that, the list of tuples on top totally made me think i was writting a 2D list the right way…maybe it was left there intentionally to troll me and make me learn it the hard way

Thanks a lot @ekaseda & @midlindner :love_you_gesture:t4:

2 Likes