def determineHours(): with open ("StudyHours.txt", "r") as file1: data = file1.readlines() total_study_hours = 0 for i, line in enumerate(data): if "error" in line: print(f"Error found in line {i + 1}: {line}") correct = input("Do you want to correct this line?(y\n)") if correct == "y": new_line = input("Enter corrected line:") data[i]=new_line for record in data: fields = record.strip().split(',') name = fields[0].title() credits = int(fields[1]) grade = fields[2] 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 {'name'}") with open ("HowManyHours.txt", 'a') as write_file: write_file.write(f"{name},{credits},{study_hours},{grade}\n") ******Here is my code, I will attach the errors I am recieving if you wouldnt mind helping me figure these out, I would appreciate it. I believe it is saying that the index field I am trying to assign isnt valid. I will also attach the file it is pulling from so you can view. The program will READ in data from a text file named StudyHours.txt. The user corrects any bad data. The program updates the information in StudyHours.txt file. For example if the file contains a letter grade of K which is not a possible letter grade. You will create and submit a text file with a minimum of 5 additional records from example below. The file is named StudyHours.txt and contains the following format: first line full name second line number of credits third line grade desired for each class
def determineHours():
with open ("StudyHours.txt", "r") as file1:
data = file1.readlines()
total_study_hours = 0
for i, line in enumerate(data):
if "error" in line:
print(f"Error found in line {i + 1}: {line}")
correct = input("Do you want to correct this line?(y\n)")
if correct == "y":
new_line = input("Enter corrected line:")
data[i]=new_line
for record in data:
fields = record.strip().split(',')
name = fields[0].title()
credits = int(fields[1])
grade = fields[2]
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 {'name'}")
with open ("HowManyHours.txt", 'a') as write_file:
write_file.write(f"{name},{credits},{study_hours},{grade}\n")
******Here is my code, I will attach the errors I am recieving if you wouldnt mind helping me figure these out, I would appreciate it. I believe it is saying that the index field I am trying to assign isnt valid. I will also attach the file it is pulling from so you can view.
The program will READ in data from a text file named StudyHours.txt. The user corrects any bad data. The program updates the information in StudyHours.txt file. For example if the file contains a letter grade of K which is not a possible letter grade. You will create and submit a text file with a minimum of 5 additional records from example below. The file is named StudyHours.txt and contains the following format:
first line full name
second line number of credits
third line grade desired for each class

![IDLE Shell 3.10.6
File Edit Shell Debug Options Window Help
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license ()" for more information.
A
A: Determine Hours to Study:
B: Determine Grade:
C: Display Averages and Totals:
D: Quit Program.
=========== RESTART: C:\Users\User\OneDrive\Desktop\F\Final Project.py ==========
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
Main Menu
Enter your menu choice: A
Traceback (most recent call last):
File "C:\Users\User\OneDrive\Desktop\F\Final Project.py", line 191, in <module>
Project.py",
line 88, in determineHours
choice_option [ch] ()
File "C:\Users\User\OneDrive\Desktop\F\Final
credits = int (fields [1])
IndexError: list index out of range
Type here to search
O
jo
(99+
I
Rain... AD
0
X
Ln: 19 Col: 0
9:26 AM
1/25/2023 125](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe4b2d486-7eb1-4e6a-9521-b0ac386b17b3%2F09997f21-a587-4692-8666-c45370221273%2Fdqsc4gr_processed.png&w=3840&q=75)

Step by step
Solved in 4 steps with 2 images









