Question: I need help with my python computer science homework. I need to make this program applicable to certain cases using if else statements . The
I need help with my python computer science homework. I need to make this program applicable to certain cases using if else statements
. The requirements are attached, below is the program I am working on. Please Help Me.
import os.path fLocation="C://TEMP//" print("Assumed file location is at: ", fLocation) fName = input(" Please enter a file name with its extension (ex. XXX.txt): ")
fin = open(fLocation + fName, 'r')
fLinesList=fin.readlines()
fin.close() print('*' * 50, " Data items have been read from file: \t" + fLocation + fName + ' ')
print('-' * 30, " The list of the lines in the file: ", fLinesList)
print(" There are", len(fLinesList), "lines ")
# Print file content line by line print(' ' + '-' * 30 + ' File "' + fName + '" contains: ') print(fLinesList[0].strip()) print(fLinesList[1].strip()) print(fLinesList[2].strip()) print(fLinesList[3].strip()) print(fLinesList[4].strip()) print(fLinesList[5].strip())
wordsInLine4 = fLinesList[4].split() print('-' * 30, " words in line4 =", wordsInLine4) QualityPointsprevious=float(wordsInLine4[6]) HoursAttemptedprevious=float(wordsInLine4[2]) GPAprevious=format(QualityPointsprevious/HoursAttemptedprevious,'.2f')
wordsInLine5 = fLinesList[5].split() print('-' * 30, " words in line5 =", wordsInLine5)
QualityPointsnow=float(wordsInLine5[6]) HoursAttemptednow=int(wordsInLine5[2]) GPAnow=format(QualityPointsnow/HoursAttemptednow,'.2f') OverallQualityPoints=QualityPointsprevious+QualityPointsnow OverallHoursAttempted=HoursAttemptedprevious+HoursAttemptednow OverallGPA=format(OverallQualityPoints/OverallHoursAttempted,'.2f') QualityPointsprevious=str(QualityPointsprevious) HoursAttemptedprevious=str(HoursAttemptedprevious) QualityPointsnow=str(QualityPointsnow) HoursAttemptednow=str(HoursAttemptednow)
save_path='C:\\TEMP\\'
text1=fLinesList[0] text2=fLinesList[1] text3=fLinesList[2] text4=fLinesList[3]
text5=fLinesList[4] text51=fLinesList[5] text6=" ---------------------------" text7=" Previous GPA:\t"+GPAprevious text8=" Current GPA:\t"+GPAnow text9=" Overall GPA:\t"+OverallGPA
text1=str(text1) text2=str(text2) text3=str(text3) text4=str(text4) text5=str(text5) text51=str(text51) text6=str(text6) text7=str(text7) text8=str(text8) text9=str(text9)
wordsInLine0 = fLinesList[0].split() print('-' * 30, " words in line0 =", wordsInLine0)
lnameofstudent=wordsInLine0[2] fnameofstudent=wordsInLine0[1]
lnameofstudent=str(wordsInLine0[2]) fnameofstudent=str(wordsInLine0[1])
name=fnameofstudent+" "+lnameofstudent
saveFile=open("C://TEMP//"+name+".txt","w")
saveFile.write(text1) saveFile.write(text2) saveFile.write(text3) saveFile.write(text4) saveFile.write(text5) saveFile.write(text51) saveFile.write(text6) saveFile.write(text7) saveFile.write(text8) saveFile.write(text9) saveFile.close()
3) After complete this assignment, your program should be able to calculate the GPAs of any student (transferred or not) as long as the student's information is stored in a file in the same format specified in the previous assignment Now, assume that all hours-attempted and quality-points stored in a file are integers in the inclusive range [0, 999], instead of [1, 999]. If both hours-attempted and quality- points at a school are zero, the GPA of a student is considered as zero from that school; If the hours-attempted is zero, but the corresponding quality-points is not zero, then the GPA from that school should be set as -1 (indicating an error has occurred); the overall GPA should be set as -1 if a GPA from a school is -1; otherwise, a GPA is determined by quality-points/hours-attempted Modify the program so that it validates the read hours-attempted and quality-points before calculating a student's GPAs Hint: To help you coding a correct program more efficiently, you should first carefully analyze and list all possible combination scenarios for hours-attempted and quality-points (2 To help you debugging the code, you could create more input data files by copying a given input data file and modifying some of its data values Note: From now on, in any program you create, which involves file operations, all logic steps depicted in Fig. 3-20 in the handout should be carried out before the program terminates, regardless whether it is stated explicitly or not in the given description for a program. 3) After complete this assignment, your program should be able to calculate the GPAs of any student (transferred or not) as long as the student's information is stored in a file in the same format specified in the previous assignment Now, assume that all hours-attempted and quality-points stored in a file are integers in the inclusive range [0, 999], instead of [1, 999]. If both hours-attempted and quality- points at a school are zero, the GPA of a student is considered as zero from that school; If the hours-attempted is zero, but the corresponding quality-points is not zero, then the GPA from that school should be set as -1 (indicating an error has occurred); the overall GPA should be set as -1 if a GPA from a school is -1; otherwise, a GPA is determined by quality-points/hours-attempted Modify the program so that it validates the read hours-attempted and quality-points before calculating a student's GPAs Hint: To help you coding a correct program more efficiently, you should first carefully analyze and list all possible combination scenarios for hours-attempted and quality-points (2 To help you debugging the code, you could create more input data files by copying a given input data file and modifying some of its data values Note: From now on, in any program you create, which involves file operations, all logic steps depicted in Fig. 3-20 in the handout should be carried out before the program terminates, regardless whether it is stated explicitly or not in the given description for a program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
