Question: Need help fixing python program: I keep getting the following when I select menu 1 after adding names to the list:line 60, in find_gpa print(mystudents.gpa)

Need help fixing python program: I keep getting the following when I select menu 1 after adding names to the list:line 60, in find_gpa print(mystudents.gpa) AttributeError: 'dict' object has no attribute 'gpa'

######################################################## Create a class named Student that holds the following data about a student: 1. Name 2. Student ID number 3. GPA 4. Expected grade in this course 5. Full time or part time Create five student objects from this class and pass data to fill in the class data above. Besides creating the objects, you will write a menu-driven program that performs the following tasks: 1. Look up and print the student GPA 2. Add a new student to the class 3. Change the GPA of a student 4. Change the expected grade of a student 5. Print the data of all the students in a tabular format 6. Quit the program ###############################################

import Students import pickle

#Global Constants

FIND_GPA = 1 ADD_STUDENT = 2 CHANGE_GPA = 3 CHANGE_GRADE = 4 PRINT_DATA = 5 QUIT = 6

FILENAME = 'students_lab10.dat'

def main(): mystudents = load_students() choice = 0 while choice != 6: choice = get_menu_choice() if choice == 1: find_gpa(mystudents) elif choice == 2: add_student(mystudents) elif choice == 3: change_gpa(mystudents) elif choice == 4: change_grade(mystudents) elif choice == 5: print_data(mystudents) save_students(mystudents)

def load_students(): try: input_file = open(FILENAME, 'rb') students_lab10_dct = pickle.load(input_file) input_file.close() except IOError: students_lab10_dct = {} return students_lab10_dct

def get_menu_choice(): print() print("Menu") print("------------------------------") print("1. Look up and print a student's GPA") print("2. Add a new student to the class") print("3. Change the GPA of a student") print("4. Change the expected grade of a student") print("5. Print the data of all the students") print("6. Quit the program") print() choice = int(input("Please enter your choice, 1-6: ")) while choice < 1 or choice > 6: choice = int(input("Please enter a valid choice, 1-6: ")) return choice

def find_gpa(mystudents): name = input("Enter a name: ") if name in mystudents: print(mystudents.gpa) else: print(mystudents.get(name, 'That name is not found.')) print()

def add_student(mystudents): name = input("Enter a new student's name: ") idn = input("Please enter the student's ID number: ") gpa = input("Please enter the student's GPA: ") grade = input("Please enter the student's expected grade in this course: ") hours = input("Please enter if this student is full or part-time: ") print() entry = Students.Students(name, idn, gpa, grade, hours) if name not in mystudents: mystudents[name] = entry print("The entry has been added.") print() else: print("That name already exists.") print()

def change_gpa(mystudents): name = input("Enter a name: ") if name in mystudents: gpa = input("Please enter the student's new GPA: ") entry = Students.Students(name, idn, gpa, grade, hours) mystudents[name] = entry print("GPA updated.") print() else: print("That name is not found.")

def change_grade(mystudents): name = input("Enter a name: ") if name in mystudents: grade = input("Please enter the student's new grade: ") entry = Students.Students(name, idn, gpa, grade, hours) mystudents[name] = entry print("Grade updated.") print() else: print("That name is not found.") print()

def print_data(mystudents): input_file = open(FILENAME, 'rb') print(mystudents) print() input_file.close()

def save_students(mystudents): output_file = open(FILENAME, 'wb') pickle.dump(mystudents, output_file) output_file.close()

main()

#########################################

# class Students class Students: def __init__(self, name, idn, gpa, grade, hours): self.__name = name self.__idn = idn self.__gpa = gpa self.__grade = grade self.__hours = hours

def set_name(self, name): self.__name = name

def set_idn(self, idn): self.__idn = idn

def set_gpa(self, gpa): self.__gpa = gpa

def set_grade(self, grade): self.__grade = grade

def set_hours(self, hours): self.__hours = hours

def get_name(self): return self.__name

def get_idn(self): return self.__idn

def get_gpa(self) return self.__gpa

def get_grade(self): return self.__grade

def get_hours(self): return self.__hours

def __str__(self): return "Name: " + self.__name + \ " IDN: " + self.__idn + \ " GPA: " + self.__gpa + \ " grade: " + self.__grade + \ " hours: " + self.__hours

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!