Question: I am finding two issues with this code. - Whenever I attempt to enter the grade, it's not accepting it. - I am not sure

I am finding two issues with this code.

- Whenever I attempt to enter the grade, it's not accepting it.

- I am not sure where to put the count 0 at the end.

I was hoping some advice could be given for the following.

def main(): """ Main function """ # Create a nested dictionary gradebook = {'Math': {'Quizzes': [], 'Tests': [], 'Assignments': [], 'Projects': []}, 'English': {'Quizzes': [], 'Tests': [], 'Assignments': [], 'Projects': []}, 'Science': {'Quizzes': [], 'Tests': [], 'Assignments': [], 'Projects': []}}

# Display the menu display_menu(gradebook)

def display_menu(gradebook): """ Display the menu """ # Display the menu print("_________________________________________") print("Welcome to the gradebook application!") print("_________________________________________") print("Please select an option from the menu below:") print("1. Record a grade") print("2. Print all grades") print("3. Calculate GPA") print("4. Exit") print("_________________________________________")

# Get the user's choice choice = input("Enter your choice: ")

# Call the appropriate function if choice == "1": record_grade(gradebook) elif choice == "2": print_grades(gradebook) elif choice == "3": calculate_gpa(gradebook) elif choice == "4": exit() else: print("Invalid choice. Please try again.")

# Display the menu again display_menu(gradebook)

def record_grade(gradebook): """ Record a grade """ # Get the subject

print("Available subjects:") print("1. Math " "2. English " "3. Science ")

subject = input("Enter the subject: ")

# Get the category print("Available categories:") print("1. Quizzes " "2. Tests " "3. Assignments " "4. Projects ")

category = input("Enter the category: ") print("Enter Grade between 0 and 100") # Get the grade grade = input("Enter the grade: ")

# Add the grade to the gradebook try: gradebook[subject][category].append(grade) except KeyError: print("Invalid subject. Please try again.")

def print_grades(gradebook): """ Print all grades """ # Print the grades print("_________________________________________") print("Printing all grades...") print("_________________________________________")

# Loop through the subjects for subject in gradebook: print("Subject: " + subject)

# Loop through the categories for category in gradebook[subject]: print("Category: " + category)

# Loop through the grades for grade in gradebook[subject][category]: print("Grade: " + grade)

def calculate_gpa(gradebook): """ Calculate GPA """ # Calculate the GPA print("_________________________________________") print("Calculating GPA...") print("_________________________________________")

# Loop through the subjects for subject in gradebook: # Loop through the categories for category in gradebook[subject]: # Loop through the grades for grade in gradebook[subject][category]: # Convert the grade to a float grade = float(grade)

# Add the grade to the total try: total = total + grade except NameError: total = grade

# Add 1 to the count count = count + 1

# Calculate the GPA try: gpa = total / count print("Your GPA is: " + str(gpa)) except: print("No grades to calculate GPA")

# Display the GPA

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!