Question
def determineHours(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
def determineHours(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() correct_errors(data)#reading in data and correcting any errors. total_study_hours = 0
for record in data: credits = int(record['credits']) grade = record['grade']
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']})
total_study_hours += study_hours#add study hours to total print(f"Total Study Hours: {total_study_hours}")#display total number of weekly study hours with open ("HowManyHours.txt", 'a') as file:#append the data alphabetically data.sort(key=lambda x: x['name'])#sort data by name
for record in data:#write data to file name = to_proper_case(record['name']) credits = record['credits'] study_hours = total_study_hours grade = record['grade'] file.write(f"{name} {credits} {study_hours} {grade} ")
This is a snippet of code I have written, we are reading data from a file called StudyHours.txt and I need to give the user the option to change the data/correct any errors before the program determines the study hours based upon the grade and writes the new information to the file.
So, instead of the correct_errors(data) code, could we get the program to display to the user what the file is currently reading and give them the option to change or correct any code before the program writes the data which has determined the amount of study hours the user must study before they can achieve their desired grade?
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