I want to write a program to read marks of 3 subjects from a file and display the highest mark of each subject with the corresponding name. so far I was able to write the program to get the highest marks but I couldn't develop it to display the corresponding name with it.
and here's my code:
def mymax(m):
m.sort()
mx=m[-1]
return mx
s1=s2=s3=[]
rfile=open("marks.txt","r")
record=rfile.readline()
while record!="":
data=record.strip("\n").split(",")
x=int(data[1])
y=int(data[2])
z=int(data[3])
s1=s1+[x]
s2=s2+[y]
s3=s3+[z]
record=rfile.readline()
print("Highest marks of subject 1:",mymax(s1))
print("Highest marks of subject 2:",mymax(s2))
print("Highest marks of subject 3:",mymax(s3))
rfile.close()
The output I want is:
Highest marks of subject 1: marks,name
Highest marks of subject 2: marks,name
Highest marks of subject 3: marks,name