I want to write a program that read multiple files and processes them in one loop.
I want to search for the id in all files and take the mark of a student.
My code is:
iD = int(input("Enter the your ID: "))
mathFile = open ('COMP2101.txt','r')
itFile = open ('STAT1001.txt','r')
bioFile = open ('BIOL2101.txt','r')
for line in mathFile and itFile and bioFile:
line = line.rstrip()
part = line.split(" ")
studentId = int(part[0])
if studentId == iD:
mathMark = part[1]
print("math",mathMark)
if studentId == iD:
itMark = part[1]
print("it",itMark)
if studentId == iD:
bioMark = part[1]
print("lbio",bioMark)
mathFile.close()
itFile.close()
bioFile.close()
How can I map the file name to if statement?
forstatement? If so, why?