calculating the average school grade which is an integer. The current code doesn't calculate the average grade correctly. Also when I enter 0 to exit it get an error (please run code on your end to find the issues with calculating the average grade and error when enter 0).

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 12PE
icon
Related questions
icon
Concept explainers
Question
100%

need help finishing Python code. I need help calculating the average school grade which is an integer. The current code doesn't calculate the average grade correctly. Also when I enter 0 to exit it get an error (please run code on your end to find the issues with calculating the average grade and error when enter 0). 

CODE 

import decimal
from decimal import Decimal

class GradeBook:   
    count = 0          
    def __init__(self, name, grades=[]):      
        self.name = name          
        GradeBook.count += 1          
        print("There are",GradeBook.count,"students in the GradeBook")     
        self.grades = []       
    def quizScore(self,score):       
        self.grades.append(score)           
    def currentAverage(self):        
        sum = 0     
        for i in self.grades:    
            sum += i   
            avg = sum/len(self.grades)     
            return avg     
name1 = input("Please enter the name for Student 1:") 
Student1 = GradeBook(name1) 
name2 = input("Please enter the name for Student 2:") 
Student2 = GradeBook(name2) 

menu = """
Grade Book

0: Exit
1: Enter quiz grade for Student 1
2: Enter quiz grade for Student 2
3: Display current grades for all students
"""
done = False 

while not done:   
    print(menu)
    selection = input('Please enter a choice: ')
 
    if selection == "0":
        done = True
        print('Exiting Grade Book Now!')  

    if selection == '1':     
        print('Student 1')     
        grade = float(input("Enter the grade for the test: "))   
        Student1.quizScore(grade)      
            
    elif selection == '2':     
        print('Student 2')     
        grade = float(input("Enter the grade for the test: "))     
        Student2.quizScore(grade)       
        
    elif selection == '3':     
        print("Current grades for Students")     
        print("Name:",Student1.name)             
        print("Current Average:",Student1.currentAverage())         
        print("Name:",Student2.name)        
        print("Current Average:",Student2.currentAverage())   
Score(" ", [])
obj.quizScore([])
obj.display()    

        

OUTPUT  OF CODE

Please enter the name for Student 1:
bob
There are 1 students in the GradeBook
Please enter the name for Student 2:
tom
There are 2 students in the GradeBook

Grade Book

0: Exit
1: Enter quiz grade for Student 1
2: Enter quiz grade for Student 2
3: Display current grades for all students

Please enter a choice: 
1
Student 1
Enter the grade for the test: 
33

Grade Book

0: Exit
1: Enter quiz grade for Student 1
2: Enter quiz grade for Student 2
3: Display current grades for all students

Please enter a choice: 
1
Student 1
Enter the grade for the test: 
22

Grade Book

0: Exit
1: Enter quiz grade for Student 1
2: Enter quiz grade for Student 2
3: Display current grades for all students

Please enter a choice: 
3
Current grades for Students
Name: bob
Current Average: 16.5
Name: tom
Current Average: None

Grade Book

0: Exit
1: Enter quiz grade for Student 1
2: Enter quiz grade for Student 2
3: Display current grades for all students

Please enter a choice: ** Process Stopped **

Press Enter to exit terminal

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT