Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, this is a code snippet I have written myself. I want someone to go over it and check to make sure that I am

Hello, this is a code snippet I have written myself. I want someone to go over it and check to make sure that I am on the right track, please feel free to comment on any code that I might be able to do easier or foolproof for the user, validating the code, and just making sure that it does what it is supposed to do. The file is going to read in from a file called StudyHours.txt and reads the data, which has:

FullName:

Credits:

Grade:

The program determines the amount of hours the user must study by this chart.

Minimum Study Hours per Week per Class Grade 15 A 12 B 9 C 6 D 0 F

After program determines how many hours the user must study based on their desired grade, the program then writes the updated material to a file called HowManyHours.txt. Hopefully I have coded all of that below but want a second opinion. I am posting what the output is supposed to look like at the very bottom and so you can get a sense of what the data looked like in Study Hours vs what it is supposed to look like post program.

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 what the file StudyHours.txt data looks like:

Full Name: Stephen Universe

Credits: 12

Grade: B

THIS IS WHAT THE OUTPUT IS SUPPOSED TO LOOK LIKE AFTER THE PROGRAM IS DONE WITH IT. Please help me with flow and validation as well

Select Option A to determine the hours for study:

Select Option B to determine the grade:

Select Option C to determine the average credits, average study hours and total

students who used the program: A

FullName: Aaron Rodgers

Grade: A

Credits: 12

WeeklyStudyHours: 60.0

You entered

K which is an incorrect value for the entered Grade

Please enter the desired grade such as A for an A:

A

FullName: Tom Brady

Grade: A

Credits: 9

WeeklyStudyHours: 45.0

FullName: Philip Rivers

Grade: c

Credits: 3

WeeklyStudyHours: 9.0

FullName: Joe Theismann

Grade: B

Credits: 15

WeeklyStudyHours: 60.0

FullName: Paul Revere

Grade: B

Credits: 15

WeeklyStudyHours: 60.0

FullName: Akbar Habib

Grade: A

Credits: 12

WeeklyStudyHours: 60.0

FullName: Steven Universe

Grade: B

Credits: 9

WeeklyStudyHours: 36.0

FullName: Barack Obama

Grade: C

Credits: 6

WeeklyStudyHours: 18.0

FullName: Harold Jenkins

Grade: A

Credits: 12

WeeklyStudyHours: 60.0

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

Question

What is the preferred personality?

Answered: 1 week ago

Question

What is the relationship between humans?

Answered: 1 week ago