§ All students have the same number of scores;
§ The total number of students is less than or equal to 10;
§ The number of scores of each student is less than or equal to 5.
(2) Computes the average score (as an integer) for each student. The average of each student is computed based on (score total / number of grades). If a student has no scores, her/his average is 0.
(3) Computes the average of the class (as an integer): class average = sum of averages / number of students;
(4) Computes the grade for each student. This time however the grade is “P” (Pass) or “NP” (No Pass): If the average of a student is greater than or equal to the class average, the student’s grade is “P”; otherwise the grade is “NP”
(5) Prints the class average. Subsequently prints the SID, the average score and the grade of each student. Note the output has to be formatted so that it can be easily read, but you can determine the exact formats.
These are the directions for an assignment i have to do, but i am extremely lost..this is what i have so far and i keep getting an error for x=float(score)
Expand|Select|Wrap|Line Numbers
- count = 0
- sum = 0
- s = raw_input("Enter SID score1 score2 score3...")
- t= s.split()
- file = open("mydata.dat","r")
- lines = file.readlines()
- file.close()
- while(s != 'q'):
- count = 0
- sum = 0
- t = s.split()
- for x in t:
- if (count == 0):
- SID = x
- else:
- sum = sum + int(x)
- count = count + 1
- no_scores = count - 1
- for line in lines:
- scores = line.split()
- count = 0
- sum = 0.0
- for score in scores:
- if count != 0:
- x = float(scores)
- sum = sum + x
- count = count + 1
- else:
- count = count + 1
- count = count - 1
- if (no_scores != 0):
- average = sum/no_scores
- else:
- average = 0.0
- grade = "NP"
- if (average >= 70):
- grade = "P"
- elif (average < 60):
- grade = "NP"
- print "Class Average:", average
- print"SID: %1s" %(SID),"Grade:", grade
- s = raw_input("Enter SID score1 score2 score3...")