I was stuck for awhile on the Python (LISTS) Gradebook Project and I found 2 solutions.
At first, I did this code incorrectly and got an error when trying to “append” to the zip.
I think a quick turnaround and I did this code Solution 1:
last_semester_gradebook = [("politics", 80), ("latin", 96), ("dance", 97), ("architecture", 65)]
subjects = ['physics', 'calculus', 'poetry', 'history']
grades = [98, 97, 85, 88]
subjects.append("computer science")
grades.append(100)
gradebook = zip(subjects, grades)
print(list(gradebook))
gradebook = list(gradebook) + [("visual arts", 93)]
full_gradebook = list(gradebook) + last_semester_gradebook
print(full_gradebook)
Then, after some research, I did Solution 2, which is probably better. Because I misread on task #3 " Use the zip()
function to combine subjects
and grades
. Save this zip object as a list
into a variable called gradebook
."
Like I did on Solution 1, line 6, just added “gradebook = zip(subjects, grades)” and did not save it as a list - as they asked.
So, I think this is the better code here:
last_semester_gradebook = [("politics", 80), ("latin", 96), ("dance", 97), ("architecture", 65)]
subjects = ['physics', 'calculus', 'poetry', 'history']
grades = [98, 97, 85, 88]
subjects.append("computer science")
grades.append(100)
gradebook = list(zip(subjects, grades))
print(list(gradebook))
gradebook.append(['visual arts', 93])
full_gradebook = gradebook + last_semester_gradebook
print(full_gradebook)
I cannot fully understand and remember all the full Python syntax and rules as I am trying to make sense of all this, I guess in time and practice!
So if you have any input and feedback, welcome.