[Tutor] Hello again. and another question.

tsmundahl at comcast.net tsmundahl at comcast.net
Thu Oct 2 23:41:37 CEST 2008


Hello Trask, 

I have been working on the first program. I got the files to read and print out the grades and averages, but when I write these files to the other txt file, all that I get is:

10.0
10.0
10.0
10.0
10.0
10.0
10.0
10.0
10.0
10.0

I know it is something simple. I am just not seeing it. Here is my code:



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."


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



I am including the files. Let me know if you see anything goofy. 



Tom Mundahl


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 1810 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/1113a35b/attachment.obj>
-------------- next part --------------
10.00
10.00
10.00
10.00
10.00
10.00
10.00
10.00
10.00
10.00
-------------- next part --------------
90.50
88.25
98.95
94.90
95.44
96.84
97.99
98.25
99.55
96.88


More information about the Tutor mailing list