#Title:         Class 11 Openning and Closing a File
#               Homework Problem 1          Open a text file with 10 grades
# Name:         Thomas Mundahl              Date: 10-1-2008
# Course:       MRPT1380 Print Media Programming
# The purpose of this program is to open a file and store the 10 grades that
# are in that file into an array. After the input loop, all the grades will be
# added up in another loop. After, the grade accumulater loop is complete, the
# average grade will be calculated. Next, print the grade average. Finally, write
# the grades out to a file that has a different name, such as grade_file_2.txt.
# In this program, 3 "for" loops will be used: 1 for input, reading all the grades
# and inputing them into an array, 1 for adding up all the grades, getting the
# total, 1 for writing out all the grades to an output file.




Grades = [ ]



filename = raw_input("Enter the filename with 10 grades to be averaged: ")



my_file_object = open (filename, "r")



for a in range (10):
    temp_string = my_file_object.readline()
    Grades = Grades + [ float (temp_string)]

my_file_object.close()

for a in range (len(Grades)):
    print "Grade", str (a + 1) + ":", Grades [a]


total = 0
for a in range (len(Grades)):
    total = total + Grades[a]

average = total/float (len(Grades))



print "The average grade was: ", round(average,2)
print ""
print "Okay, we are assuming that you have created a file named 'grade_file_2.txt' that is empty, yes?"
print ""




fname= raw_input("Please enter 'grade_file_2.txt' to write to new file: ")




grades_file_2 = open("grade_file_2.txt", "w")



for count in range (len(Grades)):
    grades_file_2.write(str("%.2f"% (len(Grades))) + "\n")




grades_file_2.close()

print ""
print "Nice Job. your file is done."

















