In Python: So this is part of a large project I am working on but I'm having a hard time finding out how to read from one text file and then correct that information to another or same txt file as well as to do it alphabetically. Any help is appreciated. The code I've added was from a previous project that was similar as to what this one wants. I can't use custom classes and I believe I'm supposed to be opening the bad information file, writing it and corrections to a temp file and then creating a new file with the right information. I'm in a beginner class and we haven't covered anything past lists. Problem #1: How much should I study outside of class? Issue: Your fellow students liked the 2nd version of study hour’s application and want to expand it again by adding the features listed below. Minimum Study Hours per Week per Class Grade 15 A 12 B 9 C 6 D 0 F Determine Hours to Study 2.1 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. StudyHours.txt contains the following data: first line full name second line number of credits third line grade desired for each class Example format StudyHours.txt file Aaron RODgers 12 A Tom brady 9 K philip Rivers apple c Joe Theismann 15 B 2.2 The program determines the total weekly study hours (for all classes) 2.3 All data must be displayed in proper case such as Bob Smith, i.e. no names should be in all lower case or all upper case or a mix such as bob or SmiTH. Use a function to convert to proper case. 2.4 The program displays the user’s name, number of credits, expected total number of weekly study hours, and desired grade 2.5 The information from 2.4 is also appended to a file named StudyHoursGrades.txt in alphabetical order (by firstname) in the following format: first line full name second line number of credits third line study hours fourth line grade Here is the code I have from previous projects: def studyHours(): #open StudentsHoursGrades.txt hoursFile = open('StudentsHoursGrades.txt', 'a') #Ask Student's Name student = input('Please enter your first and last name: \n') #Validation that something was entered while student == "": print('Please print a valid name. \n') student = input('Please enter your first and last name: \n') #Ask how many credit hours they are taking creditHours = input('How many credit hours are you taking this semester? \n') #Validate user entered a number while not creditHours.isdigit() or int(creditHours)%3!= 0: print('You entered', creditHours,'Credit hours should be divisible by 3 and not exceed 18.') creditHours = input('How many credit hours are you taking this semester? \n') #Ask what grade they desire grade = input('Please enter what letter grade you want to earn: \n') #Validate user entered a letter for grade while not((grade >= 'a' and grade <='d') or (grade == 'f') or (grade >='A' and grade <= 'D') or (grade =='F')): print('Please enter a valid letter grade of A, B, C, D, or F.') grade = input('Please enter what letter grade you want to earn: \n') #Calculate study rate if grade.upper() == 'A': studyRate = 15 elif grade.upper() == 'B': studyRate = 12 elif grade.upper() == 'C': studyRate = 9 elif grade.upper() == 'D': studyRate = 6 elif grade.upper() == 'F': studyRate = 0 #Calculate hours per class classHours = int(creditHours)/3 #Calculate study hours hours = int(classHours) * studyRate #write to file hoursFile.write(str(student) + '\n') hoursFile.write(str(creditHours) + '\n') hoursFile.write(str(hours) + '\n') hoursFile.write(grade + '\n') #close file hoursFile.close() #display on screen print('Name: ',student) print('Credits: ',creditHours) print('Study Hours: ',hours) print('Letter Grade: ',grade, '\n')
In Python: So this is part of a large project I am working on but I'm having a hard time finding out how to read from one text file and then correct that information to another or same txt file as well as to do it alphabetically. Any help is appreciated. The code I've added was from a previous project that was similar as to what this one wants. I can't use custom classes and I believe I'm supposed to be opening the bad information file, writing it and corrections to a temp file and then creating a new file with the right information. I'm in a beginner class and we haven't covered anything past lists.
Problem #1: How much should I study outside of class?
Issue:
Your fellow students liked the 2nd version of study hour’s application and want to expand it again by adding the features listed below.
Minimum Study Hours per Week per Class Grade
15 A
12 B
9 C
6 D
0 F
- Determine Hours to Study
- 2.1 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.
StudyHours.txt contains the following data:
- first line full name
- second line number of credits
- third line grade desired for each class
Example format StudyHours.txt file
Aaron RODgers
12
A
Tom brady
9
K
philip Rivers
apple
c
Joe Theismann
15
B
- 2.2 The program determines the total weekly study hours (for all classes)
- 2.3 All data must be displayed in proper case such as Bob Smith, i.e. no names should be in all lower case or all upper case or a mix such as bob or SmiTH. Use a function to convert to proper case.
- 2.4 The program displays the user’s name, number of credits, expected total number of weekly study hours, and desired grade
- 2.5 The information from 2.4 is also appended to a file named StudyHoursGrades.txt in alphabetical order (by firstname) in the following format:
- first line full name
- second line number of credits
- third line study hours
- fourth line grade
Here is the code I have from previous projects:
def studyHours():
#open StudentsHoursGrades.txt
hoursFile = open('StudentsHoursGrades.txt', 'a')
#Ask Student's Name
student = input('Please enter your first and last name: \n')
#Validation that something was entered
while student == "":
print('Please print a valid name. \n')
student = input('Please enter your first and last name: \n')
#Ask how many credit hours they are taking
creditHours = input('How many credit hours are you taking this semester? \n')
#Validate user entered a number
while not creditHours.isdigit() or int(creditHours)%3!= 0:
print('You entered', creditHours,'Credit hours should be divisible by 3 and not exceed 18.')
creditHours = input('How many credit hours are you taking this semester? \n')
#Ask what grade they desire
grade = input('Please enter what letter grade you want to earn: \n')
#Validate user entered a letter for grade
while not((grade >= 'a' and grade <='d') or (grade == 'f') or (grade >='A' and grade <= 'D') or (grade =='F')):
print('Please enter a valid letter grade of A, B, C, D, or F.')
grade = input('Please enter what letter grade you want to earn: \n')
#Calculate study rate
if grade.upper() == 'A':
studyRate = 15
elif grade.upper() == 'B':
studyRate = 12
elif grade.upper() == 'C':
studyRate = 9
elif grade.upper() == 'D':
studyRate = 6
elif grade.upper() == 'F':
studyRate = 0
#Calculate hours per class
classHours = int(creditHours)/3
#Calculate study hours
hours = int(classHours) * studyRate
#write to file
hoursFile.write(str(student) + '\n')
hoursFile.write(str(creditHours) + '\n')
hoursFile.write(str(hours) + '\n')
hoursFile.write(grade + '\n')
#close file
hoursFile.close()
#display on screen
print('Name: ',student)
print('Credits: ',creditHours)
print('Study Hours: ',hours)
print('Letter Grade: ',grade, '\n')
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images