Question
print('Welcome user to the Grade Calculator Version 2.0. I thank you for continuing support for this program. This allows us to continue focusing on making
print('Welcome user to the Grade Calculator Version 2.0. I thank you for continuing support for this program. This allows us to continue focusing on making apps you will love. Thanks.Programmer:Shonda Deese')
studentsName = [""] * (10) grade = [""] * (10) credts = [0] * (10) hours = [0] * (10) creditSum = 0 avgHours = 0
MinHours = { #defining the minimum number of study hours per week for each letter grade. "A": 15, "B": 12, "C": 9, "D": 6, "F": 0 } #creating a class for student information class Student: def __init__(self, name, employee_id, department, credits, desired_grade): self.name = name self.employee_id = employee_id self.department = department self.credits = credits self.desired_grade = desired_grade self.study_hours = MinHours[desired_grade] * credits
def __str__(self): return f"{self.name}, Credits: {self.credits}, Study Hours: {self.study_hours}, Grade: {self.desired_grade}"
#creating class to represent the report with all desired information.
class Report: def __init__(self, creator, employee_id, department, report_for, report_employee_id, report_department): self.creator = creator self.employee_id = employee_id self.department = department self.students = [] self.report_for = report_for self.report_department = report_department self.report_employee_id = report_employee_id
def add_student(self, student):#adds a student to the list of students self.students.append(student)
def determine_hours(self):#reads data from the StudyHours.txt file, creates an object for each entry, and displays the information, eventually writing the data to HowManyHours.txt #opening StudyHours.txt in read mode with open ("StudyHours.txt", "r") as file1: data = file1.readlines()
for i in range(0, len(data), 3): name = data[i].strip().title() credits = int(data[i+1].strip()) grade = data[i+2].strip().upper() student = Student(name, self.employee_id, self.department, credits, grade) self.add_student(student)
#Sort the students by name self.students.sort(key=lambda s: s.name)
#Display the students' information for student in self.students: print(student)
#Write the student's information to HowManyHours.txt with open("HowManyHours.txt", "w") as file2: for student in self.students: file2.write(f"{student.name} {student.credits} {student.study_hours} {student.desired_grade} ") def determine_grade(self): Grades = open("Grades.txt","r") HowManyHours = open("HowManyHours.txt","a")
for line in Grades: name, crdits, hours = line.split() name = string.capwords(name)
if int(crdts) > 0 and int(crdts) <= 30: if int(hours) >= 90: grade = "A" elif int(hours) >= 60: grade = "B" elif int(hours) >= 30: grade = "C" else: grade = "F"
#write the student's name, credits, hours, and grade to the howmanyhours file. HowManyHours.write(name + " " + crdts + " " + hours + " " + grade + " ") Grades.close() HowManyHours.close()#close the files. def display_averages_and_totals(self):
for i in range (1, 2 + 1, 1): print("Enter student's name") studentsName[i] = input() print("Enter credits") credts[i] = int(input(creditSum = credts[i] + creditSum print("Enter study hours") hours[i] = int(input()) avgHours = hours[i] + avgHours creditSum = float(creditSum) / i avgHours = float(avgHours) / i print("Total Students:" + str(i)) print("Average Credits:" + str(creditSum)) print("Average Study Hours:" + str(AvgHours))
#Defining our main function def main():#displaying menu options while True: print("Menu:") print("A. Determine Hours to Study") print("B. Determine Grade") print("C. Display Averages and Totals") print("D. Quit")
#Prompt the user for their menu choice choice = input("Enter your choice:").upper()
#Creating the report.
name = input("Enter your name: ").title() while name == "": #validate the user entered information print("Please enter a valid full name.") name = input("Enter your name: ").title() employee_id = input("Enter your employee id: ") while not employee_id.isdigit():#validate user entered information print('Please enter a valid employee id.') employee_id = input("Enter your employee id: ")
department = input("Enter your department: ").title() while department == "":#validate user entered information print('Please enter a valid department.') department = input("Enter your department: ").title()
report_for = ("Enter the name of the person the report is for: ").title() while report_for == "":#validate user entered information print('Please enter valid name of who the report is for.') report_for = ("Enter the name of the person the report is for: ").title()
report_employee_id = input("Enter their employee id: ") while not report_employee_id.isdigit():#validate user entered information print('Please enter a valid employee id.') report_employee_id = input("Enter their employee id: ")
report_department = input("Enter their department: ").title() while report_department == "":#validate user entered information print('Please enter a valid department.') report_department = input("Enter their department: ").title()
report = Report(name, employee_id, department, report_for, report_employee_id, report_department) if choice == "A": report.determine_hours() elif choice == "B": report.determine_grade() elif choice == "C": report.display_averages_and_totals() elif choice == "D": break else: print("invalid option, please try again") main() #calling the main function
****Here is my code. I cannot get the main menu to work. It displays all of the correct menu options but immediately goes into the report selection regardless of what I do. I need to create a menu that will execute the different functions I have in the program.
Again the menu is right but regrdless of the selection i choose it doesnt go into the code under that specific menu option.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started