Home / Forum

# Forum

Forum breadcrumbs - You are here:
You need to log in to create posts and topics.

# Create a python application that will process student test scores.

Create a python application that will process student test scores.

89

77

92

69

87

62

55

78

31

90

Write an application that will

1. open the file

2. read in the scores

3. if a score is 70 or higher, add 1 to the total of passing scores

4. if a score is less than 70, add 1 to the total number of failing scores

5. Print out the total number of passing and failing scores, and the overall average. It should look something like this (your numbers will be different):

Number failed: 4

Number passed: 6

Class average: 78.2

Solution

filename = input('Enter the filename: ')
fh = open(filename, 'r')
count = 0;
classAvg = None
total = 0
numPass = 0
numFail = 0

while count < len(lines):
score = int(lines[count])
total = total + score
if score >= 70:
numPass = numPass + 1
else:
numFail = numFail + 1

count = count + 1

classAvg = total / count

print("Number failed: {}".format(numFail))
print("Number passed: {}".format(numPass))
print("Class Average : {:.2f}".format(classAvg))

input file: scores.txt
-------
89
77
92
69
87
62
55
78
31
90

output
----
Enter the filename: scores.txt
Number failed: 4
Number passed: 6
Class Average : 73.00