This is the code I have written for my final proect. I am running into problems with the menu, I am thinking maybe I have it indented wrong somewhere or something. When I run the program it pops up A is not defined when it clearly is. I am not sure what it meant. This is the way I did the last menu in the las menu driven program I coded and it worked fine. Please help, answer in Python only. I am going to take out a lot of the code so I can submit the question but will leave what I think i relevant to my problem. My menu options are the functions determineHours, determine_grade, and display_averages_and_totals. You will see how I have it coded at the bottom but it isnt working please help. SO AGAIN, I TOOK A LOT OF CODE OUT TO MAKE THIS QUESTION FIT but it doesnt seems to be selecting the options correctly, it says A is not defined.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is the code I have written for my final proect. I am running into problems with the menu, I am thinking maybe I have it indented wrong somewhere or something. When I run the program it pops up A is not defined when it clearly is. I am not sure what it meant. This is the way I did the last menu in the las menu driven program I coded and it worked fine. Please help, answer in Python only. I am going to take out a lot of the code so I can submit the question but will leave what I think i relevant to my problem.

My menu options are the functions determineHours, determine_grade, and display_averages_and_totals. You will see how I have it coded at the bottom but it isnt working please help. SO AGAIN, I TOOK A LOT OF CODE OUT TO MAKE THIS QUESTION FIT but it doesnt seems to be selecting the options correctly, it says A is not defined.


                     lines = file

def determineHours():
       def correct_errors(data):

              if "error" in line:#check if there are errors
                     print(f"Error found in line {i + 1}: {line}")
                     correct = input("Do you want to correct this line? (y/n)")#give user option to correct any errors
                     if correct == "y":
                            new_line = input("Enter corrected line:")
                            data[i] = new_line
       with open ("StudyHours.txt", "r") as file1:
              data = file1.readlines()
              correct_errors(data)#reading in data and correcting any errors.
              total_study_hours = 0

       def to_proper_case(name):#defining to_proper_case function
              return name.title()
       for record in data:
              fields = record.strip().split(',')
              name = fields[0]
              credits = int(fields[1])
              grade = fields[2]

              

              if grade == 'A':#determine weekly study hours based on desired grade
                     study_hours = 15 * credits
              elif grade == 'B':
                     study_hours = 12 * credits 
              elif grade == 'C':
                     study_hours = 9 * credits
              elif grade == 'D':
                     study_hours = 6 * credits
              elif grade == 'F':
                     study_hours == 0
              else:
                     print("Invalid grade for student {record['name']}")

                     
                            
                                  
                                  
                     
def determine_grade():
       try:#creating this block to handle any exceptions that might occur when trying to convert.
              with open("Grades.txt", "r") as file:#open Grades to read data
                     with open ("HowManyHours.txt", "a") as writeFile:#append data to HowManyHours
                            grade_map = {15:"A",12:"B",9:"C",6:"D",0:"F"}#defining the dictionary
                            for line in file:
                                   line_list = line.split()#splitting lines into a list
                                   

       file.close()
       writeFile.close()
       
def display_averages_and_totals(self):
       try:
              with open ("HowManyHours.txt", "r") as file:#read data from file
                     data = file.readlines()
       except FileNotFoundError:
              raise FileNotFoundError("HowManyHours.txt is not found.")

              
              total_credits = 0
              total_study_hours = 0
              total_students = 0

              for line in data:
                     values = line.strip().split(",")#using a delimiter to split the line into a list of values
                     student = values[0]
                     total_credits += int(values[1])
                     total_study_hours += int(values[2])
                     grade = values[3]

                     total_students += 1#calculating total students
              average_credits = total_credits / total_students#calculating average credits.
              average_study_hours = total_study_hours / total_students#calculating average study hours.

    
       

if __name__ == '__main__':
       print('\t\t\tMenu')#main menu 
       print('A: Determine Hours to Study:')
       print('B: Determine Grade:')
       print('C: Display Averages and Totals:')
       print('D: Quit Program')
       ch= input('\nEnter your menu choice:').upper()
       choice_option = {#menu options the user gets to choose from
              A: determineHours,
              B: determine_grade,
              C: display_averages_and_totals,
              D: quit
       }
       choice_option[ch]()

       print("Thank you for using the Grade Calculator 2.0. Your support allows us to continue making apps you will love. Thank you.")
              
           
            
              
              

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Graphical User Interface
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education