Home / Expert Answers / Computer Science / please-help-using-a-text-editor-or-ide-copy-the-following-list-of-names-and-grade-scores-and-save-i-pa315

(Solved): PLEASE HELP Using a text editor or IDE, copy the following list of names and grade scores and save i ...



PLEASE HELP

Using a text editor or IDE, copy the following list of names and grade scores and save it as a text file named scores.txt:


Name,Score
Joe Besser,70
Curly Joe DeRita,0
Larry Fine,80
Curly Howard,65
Moe Howard,100
Shemp Howard,85


Create a Python program that displays high, low, and average scores based on input from scores.txt. Verify that the file exists and then use string functions/methods to parse the file content and add each score to an array. Display the array contents and then calculate and display the high, low, and average score. Format the average to two decimal places. Note that the program must work for any given number of scores in the file. Do not assume there will always be six scores. Use separate functions for input, processing, and output.

BELOW IS WHAT I HAVE SO FAR:

def read_scores(filename):
scores = []
try:
file = open("scores.txt")
content = file.readline()
while True:
content = file.readline()
if not content:
break
split_str = content.split(',')
scores.append(int(split_str[1].strip()))
except Exception as exception:
print(exception)


def calculate_scores(scores):
if scores:
highest = max(scores)
lowest = min(scores)
average = sum(scores) / len(scores)
return highest, lowest, average
else:
return None


def display_result(scores, highest, lowest, average):
print("Scores: ", scores)
print("\nHighest Score: ", highest)
print("Lowest Score: ", lowest)
print("Average Score: " + "{:.2f}".format(average))


def main():
filename = "scores.txt"
scores = read_scores(filename)
if scores:
highest, lowest, average = calculate_scores(scores)
display_result(scores, highest, lowest, average)


main()

it's not showing any results.



We have an Answer from Expert

View Expert Answer

Expert Answer



There are a couple of i...
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe