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!!!

20th Feb 2019, 12:04 PM
Student
Student  - avatar
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]
20th Feb 2019, 12:47 PM
strawdog
strawdog - avatar
0
wow I see , thanks alot
20th Feb 2019, 1:05 PM
Student
Student  - avatar