In: Computer Science
using JUPYTER notebook:
9.1 (Class Average: Writing Grades to a Plain Text File) Figure 3.2 presented a classaverage script in which you could enter any number of grades followed by a sentinel value, then calculate the class average. Another approach would be to read the grades from a file. In an IPython session, write code that enables you to store any number of grades into a grades.txt plain text file.
In an IPython session, write code that reads the grades from the grades.txt file you created in the previous exercise. Display the individual grades and their total, count and average.
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to copy:
f=open("grades.txt",'r')#open file in read mode
l=list(f.readlines())
print("The grades are:")
for i in range(len(l)):
l[i]=int(l[i][:-1])#convert grade to int type and remove new line
characters
print(l[i])#print the grades
print("The total is:",sum(l))#print the total grades
print("The count is: ",len(l))#print number of grades
print("The average is: ",sum(l)/len(l))
Note:
Please let me know in case of any help needed in the comments section.
Plese upvote my answer. Thank you.