Getting List Index Range Error Fix Def Storedanswerkeyfile Filename Correctanswerslist Ans Q43821687
Why am I getting a list index out of range error how can I fix it? def storedAnswerKey_File( fileName, correctAnswers_list): AnswerKey_File = open( fileName, “w”) totalQuestions = len( correctAnswers_list) for userAnswer_Index in range( totalQuestions ): userAnswer = input( “Enter your answer for question ” + str( (userAnswer_Index + 1 ) ) + “: ” ) AnswerKey_File.write(userAnswer + “n” ) AnswerKey_File.close()def FTLStoredAnswerKey_File ( fileName ): AnswerKey_File = [] storedAnswerKey_File = open( fileName, “r” ) for finalAnswer in storedAnswerKey_File: AnswerKey_File.append( finalAnswer ) return AnswerKey_Filedef totalCorrectAnswers( finalCorrectAnswer_list, enteredAnswer_list ): correctAnswers = 0 totalQuestions = len( finalCorrectAnswer_list) for current_QuestionIndex in range( totalQuestions ): if enteredAnswer_list[ current_QuestionIndex ] == finalCorrectAnswer_list[ current_QuestionIndex ]: correctAnswers = correctAnswers + 1 return correctAnswersdef totalIncorrectAnswers( enteredCorrectAnswers, enteredQuestions ): enteredIncorrectAnswers = enteredQuestions – enteredCorrectAnswers return enteredIncorrectAnswersdef collectIncorrectAnswers( finalCorrectAnswer_list, enteredAnswer_list ): incorrectQuestions_list = [] totalQuestions = len( finalCorrectAnswer_list ) for current_QuestionIndex in range( totalQuestions ): if enteredAnswer_list[current_QuestionIndex] != finalCorrectAnswer_list[ current_QuestionIndex ]: incorrectQuestions_list.append( current_QuestionIndex + 1 ) return incorrectQuestions_listdef examPass( finalPassmark, enteredAnswer_list ): if len (enteredAnswer_list ) >= finalPassmark: return True else: return Falsedef printValues_list( anyList ): for currentValueIndex in range( len( anyList) ): print( anyList[ currentValueIndex ] )def printResults( entireExamAnswers_correct, entireExamAnswers_incorrect, entireExamAnswers_incorrectlist ): print( “Total Correct Answers: ” + str( entireExamAnswers_correct), “Total Incorrect Answers: ” + str( entireExamAnswers_incorrect ) ) printValues_list( entireExamAnswers_incorrectlist )def main(): correctAnswers_list = [“B”, “D”, “A”, “A”, “B”, “A”, “B”, “A”, “C”, “D”, “B”, “C”, “D”, “A”, “D”, “C”, “C”, “B”, “D”, “A”] Number_of_Questions = len(correctAnswers_list) FILE_NAME = ” studentAnswers.txt ” Pass_Mark = 15 storedAnswerKey_File( FILE_NAME, correctAnswers_list ) studentAnswersList = FTLStoredAnswerKey_File( FILE_NAME ) num_correctAnswers = totalCorrectAnswers(correctAnswers_list, studentAnswersList ) num_incorrectAnswers = totalIncorrectAnswers( num_correctAnswers, Number_of_Questions ) incorrectQuestions_list = collectIncorrectAnswers( correctAnswers_list, studentAnswersList) printResults( num_correctAnswers, num_incorrectAnswers, incorrectQuestions_list ) if examPass( Pass_Mark,studentAnswersList): print(” The Student passed the exam”) else: print(” The Student did not pass the exam”)main()
Expert Answer
Answer to Why am I getting a list index out of range error how can I fix it? def storedAnswerKey_File( fileName, correctAnswers_l…
OR