I am trying to write a program in PYTHON that will open a file named StudyHours.txt. The program will read in data from a text file named StudyHours.txt. The user of the program will be prompted to correct any bad data. The program updates the corrected information in StudyHours.txt file. For example if the file contains a letter grade of K which is not a possible letter grade(possible grades are A,B,C,D,F). The StudyHours.txt file contains this info: Aaron Rodgers 12 A Tom Brady 9 K Philip Rivers 3 c Joe Theismann 15 B As you can see there is a K listed for a grade for Tom Brady. How do I change that K to a valid grade by prompting an input from the user and then recording that change in the StudyHours.txt file so that the file reads: Aaron Rodgers 12 A Tom Brady 9 A (changed from K to what the user inputs)- say the user inputs an A Philip Rivers 3 c Joe Theismann 15 B This is what I have to start with. Assume the file is opened and the \n is stripped. while gradeDesired > 'F' or gradeDesired == 'E': print('Invalid grade! Enter a grade of A,B,C,D, or F') gradeDesired = input('Enter a correct grade of A,B,C,D, or F ) So when the user enters an A, I need the program to change that K to an A within that StudyHours.txt file. Thanks, Gary
I am trying to write a program in PYTHON that will open a file named StudyHours.txt. The program will read in data from a text file named StudyHours.txt. The user of the program will be prompted to correct any bad data. The program updates the corrected information in StudyHours.txt file. For example if the file contains a letter grade of K which is not a possible letter grade(possible grades are A,B,C,D,F). The StudyHours.txt file contains this info:
Aaron Rodgers
12
A
Tom Brady
9
K
Philip Rivers
3
c
Joe Theismann
15
B
As you can see there is a K listed for a grade for Tom Brady. How do I change that K to a valid grade by prompting an input from the user and then recording that change in the StudyHours.txt file so that the file reads:
Aaron Rodgers
12
A
Tom Brady
9
A (changed from K to what the user inputs)- say the user inputs an A
Philip Rivers
3
c
Joe Theismann
15
B
This is what I have to start with. Assume the file is opened and the \n is stripped.
while gradeDesired > 'F' or gradeDesired == 'E':
print('Invalid grade! Enter a grade of A,B,C,D, or F')
gradeDesired = input('Enter a correct grade of A,B,C,D, or F )
So when the user enters an A, I need the program to change that K to an A within that StudyHours.txt file.
Thanks,
Gary
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images