Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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} ")

I need someone to help me make the following changes or rewrite the code to avoid errors and to make sure its running properly:

I need to define the correct_errors function or write PYTHON code that would give the user an option to change the line that the file is reading in.

Kind of the same scenario as above, I have to define to_proper_case in my code prior to it being used. I need to define it or find another way.

I need make sure the data.sort(key = lambda x: x['name']) is defined before the dtermineHours function is used.

PPPPPPLLLLLEASE, help me with these corrections so I can be done with this. PYTHON LANGUAGE PLEASE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions