Question: python help me. Given the following data file data.txt. Write a Python program to read the class name and a series of scores then find
python help me.
Given the following data file "data.txt". Write a Python program to read the class name and a series of scores then find the average, the lowest and the highest score for the class and print the result in the form shown below.
Sample Input file: CSci 1 90 100 89 78 67 Output format: Class High Low Average CSci1 100 67 77.5
my code is not worked
my code:
fileName = input("Enter file name and path: ")
fin = open(fileName)
ct = 0
total = 0
cla=str(fin)
for line in fin:
x = int(line)
if ct == 0:
high = x
low = x
else:
if high < x :
high = x
elif low > x :
low = x
total += x
ct += 1
if ct > 0 :
avg = total /ct
print( "%-20s%-15s%-15s%-15s%"%("Class","High","Low","Average" ))
print("%-20s%-15f%-15f%-15f%"%(cla, higt, low, avg))
else:
print("No data was processed. ")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
