0
how can I read lines of students ID and their answers then split the ID from answers?
I am trying to read a file that contain the ID of students and their answers of multiple choices ...when I wrote this code : file = input('please enter the exame file: ') inputfile = open(file+'.txt','r') modaleAnswer = inputfile.readline() print (modaleAnswer) for lines in inputfile: lines.split() ID = lines[0] answer = lines[1] it give me this: please enter the exame file: inpot abcdefabcdefabcdefab 1 9 5 4 3 instead of two fields!!!
2 Answers
0
lines.split() supposed to return an array. but you did not provide a variable to which to return it.
try this:
fields = lines.split()
ID = fields[0]
answer = fields[1]
OR:
ID, answer = lines.split()[:2]
0
wow
I see , thanks alot