저는 파이썬을 처음 접했고 이번 학기에 시작했습니다. 올바른 답을 취하고 목록으로 저장하는 코드를 작성한 다음 txt 파일의 20 개 질문에 대한 학생 응답을 읽고 다른 목록에 답변을 저장하는 방법을 찾는 데 어려움을 겪고 있습니다. 그 후에 목록을 비교하고 답을 인쇄하고 학생이 합격했는지 여부 (15 자 이상이 합격인지)와 정확한 총 수 및 잘못된 총 수를 나타내는 메시지가 프로그램에 표시됩니다. 예를 들어 A, C, A, A, D, B, C, A, C, B, A, D, C, A, D, C, B, 학생 대답은 테스트 할 자신 만의 텍스트 파일을 만들 것입니다. 어떤 도움도 내 현재 형식이 작동하지 않는 것 같아서 아래에 나와 있습니다.()Python을 사용하여 목록 비교하기?
데프 주 :
total = 0
index = 0
answers = [ 'A', 'C', 'A', 'A', 'D',\
'B', 'C', 'A', 'C', 'B',\
'A', 'D', 'C', 'A', 'D',\
'C', 'B', 'B', 'D', 'A']
student_answers = open('student_solution.txt', 'r')
for answer in student_answers:
print(answer.strip())
while index in answers == student_answers:
if student_answers[0] == answers[0]:
total +=1
else:
total +=0
student_answers.close()
print('Total correct answers: ', total)
print('Total of incorrect answers: ', 20 - total)
if total >= 15:
print('Congratulations! You passed the exam.')
else:
print('Sorry, you have failed the exam.')
주()
은 여전히 여기에 문제를 줄 것으로 보인다 업데이트 된 프로그램입니다. 내가 사용 학생의 대답은 ACAADBCACBADCADCBBDAC AADBCACBADCADCBBDD()
데프 주요 있습니다
total = 0
index = 0
answers = [ 'A', 'C', 'A', 'A', 'D',\
'B', 'C', 'A', 'C', 'B',\
'A', 'D', 'C', 'A', 'D',\
'C', 'B', 'B', 'D', 'A']
infile = open('student_solution.txt', 'r')
student_answers = infile.readline()
infile.close()
print(student_answers)
for answer in student_answers:
for y in range(len(answer)):
if answer[y] == answers[y]:
total += 1
print('Total correct answers: ', total)
print('Total of incorrect answers: ', 20 - total)
if total >= 15:
print('Congratulations! You passed the exam.')
else:
print('Sorry, you have failed the exam.')
주()
:'이 일을하지 않는 질문은 당신이 그것을 –
을하고 있다고 생각이 되었습니까? –