[Tutor] Hello and some questions.
Hello all. I recently starting taking Python in my state college. I joined the Python.org users group and I posted a couple of codes examples that I was having problems with, and I am wondering if there is anyone in this community that can help me. I did get some great advice on my previous posts however my code is still not working. I have two problems that I have to write code for. The first problem is a program that will take a list of ten grades from a user and then calculate the average of the ten numbers entered. The user can only use the numbers 1-10. Example. "The total average of the grades you entered in was 5" which would be the average using number 1-10 in a sequence, but it needs to calculate an average no matter if the user puts in 3 "5's" and 7 "10's". The average must be calculated. I did get some help in the python forums with this and I have come up the following, but I am getting a syntax error on the line that calls out "total" as a variable. Here is the code: value = [ ] for i in range(10): range += 1 print (int(float(raw_input("Please enter a grade, use numbers 1 - 10: "))) # getting a syntax error on this line total = sum(value) average = total/10.0 print "The average sum of all of the grades that you entered is ", ("%.2f" % average) raw_input("\nPlease hit enter to quit.") ///The code does not work. The next problem is supposed to use the while loop. A user is supposed to enter some grade values. The user will continue to be prompted to enter grade values until the user has entered in "" as a grade value. Then the program is supposed to calculate the average of all of the grades entered including the . Here is my code, This code is not working either: target = value = [ ] while i in value < or not == target: i += 1 print grade (int(float(raw_input("Please enter a grade: "))) total = sum(value) average = total/target print "The average grade that you entered is ", ("%.2f" % average) raw_input("Please hit enter to exit.") ///Can anyone tell me what I am doing wrong on either of these problems? I know it is a logic error, but I am new to this so please bare with me. Again, thanks for your help. I am new to this forum so please have patience with me when I am posting. Thank you, Thomas Mundahl ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello again. and another question.
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 tm_week11_problem1.py Description: Binary data 10.00 10.00 10.00 10.00 10.00 10.00 10.00 10.00 10.00 10.00 90.50 88.25 98.95 94.90 95.44 96.84 97.99 98.25 99.55 96.88___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor