Completed Gradebook Project/ How to clean Up

Completed Code

Hello I completed the Grade Book challenge for the Python module and would like tips for formatting the code more efficiently. I got through the code but it just seems “off” to me. Any Suggestions?

#I included a link to the project and will Copy and paste the code below, thanks in advance for any suggestions.

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

Your code below:

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

gradebook = [
[“physics”, 98],
[“calculus”, 97],
[“poetry”, 85],
[“history”, 88]
gradebook.append([“computer science, 100”])
gradebook.append([“visual arts, 93”])
gradebook[-1][-1] = ‘visual arts, 98’



full_gradebook = last_semester_gradebook + gradebook


Hi Remmy,

Your code looks great. One thing I did notice; look at the data structure of gradebook:

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

It is list[‘str’, int]. However; when you attempt to append computer science, and visual arts to grade book, the data structure is: list[‘str’]

gradebook.append(["visual arts, 93”])

It should be:

gradebook.append(["visual arts", 93])

Also, when you append pass; just pass a str, not a list like so:


If you want tips on formatting the code more efficiently, you could write the code in a function:

def get_full_grade_book(last_semester, grade_book):
    # append computer science to grade_book:
    grade_book.append(["computer science", 100])

    # append visual arts to grade_book
    grade_book.append(["visual arts", 93])
    print('Computer Science & Visual Arts added --> ',grade_book)

    # change visual arts grade:
    grade_book[-1][-1] = 98
    print('Visual Arts grade changed to 98 --> ',grade_book)

    # remove poetry grade:
    print('Poetry grade of 85 removed --> ', grade_book)

    # add grade of pass for poetry class:
    print('Poetry grade of pass added --> ', grade_book)

    # Return full grade_book
    return last_semester + grade_book

if __name__ == '__main__':
    last_semester_grade_book = [["politics", 80], ["latin", 96], ["dance", 97], ["architecture", 65]]
    grade_book = [["physics", 98], ["calculus", 97], ["poetry", 85], ["history", 88]]

    print(get_full_grade_book(last_semester_grade_book, grade_book))

Let me know if this helps you out!

1 Like

Thank you a lot, this really helped my understanding, idk how i missed that quotation lol, thanks again