Question
This is the code I have so far, I previously posted this question and it was answered in Java instead of what I need which
This is the code I have so far, I previously posted this question and it was answered in Java instead of what I need which is PYTHON. Please put it in python language. I am going to post the code I have written and what the end result is supposed to look like and just wanna make sure it is going to work and is right.
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} ")
Above is what i have written to hopefully come out as the below.I need to make sure it comes out as the below:
Select Option A to determine the hours for study:
Hours of study are determined by the information provided:
Minimum Study Hours per Week per Class Grade 15 A 12 B 9 C 6 D 0 F
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.
Data must be validated. Each class is 3 credits, and we assume the same study hours and grades for all classes. We have to validate all user entered data to make sure they entered something, a letter is a letter and validate a number when it is supposed to be a number, the max credits that can be taken is 55. Use the minimum study hour chart to grade table to determine if needed.
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