Question
I have been trying to read, write, append to a txt file by using Python 3.5 for days, bit with no success! please, could anyone
I have been trying to read, write, append to a txt file by using Python 3.5 for days, bit with no success! please, could anyone help me out? attached are the requirement.. I tried to follow the book, but for some wired reasons it gives me error every time I run it! here is my codes: "
def main(): with open("project3-scores.txt") as f_contents:
contents = f_contents.raed()
inFile.close()
print(file_contents)
score = list()
count = 0
avg = 0
finFile = input("Please enter the scores filename: ")
try: f_output = open("averages.csv", "a") f_output.write('Student name, Student grade')
f_Handle = open("filename") print("opening file {0}".format(filename))
for retrieving in f_Handle: try: score.ppend(float(retrieving)) count = count +1 if count ==4:
for num in score: avg = avg +num avg = avg / 4 print("{0} scores: {1}, {2}, {3}, {4}, average: {5}"," " .format(name, score[0], score[1], score[2], score[3], avg)) f_output.write(' {0}]t{1}'.format(name, avg))
count = 0
avg = 0 score.clear() except: user = retrieving for retrieving in result: print(retrieving)
except IOError as err:
print("Sorry,could not open scores file ", "ileDoesNotExist.txt", "!")
else: f_Handle.close() f_output.close()
main() " P.S. I am not a Computer Science major, that's why!!
below are the requirments:
Description: Write a python script (with comments) that commutes the average score for an unknown number of students in a file. Specifically your script should: .Ask for a filename name (that has scores in it) Open the scores file .Verify the scores file opened correctly Read the student's name and their four scores Display the student's name, all of their scores and their average to the screen Writes the students name and the scores' average to a file name "averages.csv Close both files Examples For example, the following are examples of correct execution (with the text in bold being the input from the user) project3-scores.txt Output file averages.csv" Input file Output to the screen: Please enter the scores filename : project3-scores.txt # Student name, grade average Opening scores file project3-scores.txt Mary scores: 76.0 89.0 82.0 100.0 average: 86.75 Joey scores: 91.0 81.0 83.0 95.0 average: 87.5 Sally scores: 92.0 93.0 90.0 97.0 average: 93.0 Mary 76 89 82 100 Joey 91 81 83 95 Sally 92 93 90 97 Mary,86.75 Joey, 87.5 Sally,93.0Step 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