Note that there are some explanatory texts on larger screens.

plurals
  1. POPython 3.3 - Multiple choice reading from list and .txt then grade
    primarykey
    data
    text
    <p>I have tried this program in three different ways I know I got close several times but after failing so many times I have given up and need an extra set of eyes. The program is "simple" I know but I know I am over thinking it.</p> <p>Program should store correct answers in a list. Using that list to grade the 20 question test. Then read that student.txt file to determine how the student answered. After reading the .txt file it should grade then display pass or fail (passing = 15 or greater) It finally displays the total number or correct, incorrect answers with a list of the questions missed by the student. </p> <p>Below are all three attempts. Any help is greatly appreciated.</p> <hr> <pre><code>answerKey = [ B, D, A, A, C, A, B, A, C, D, B, C, D, A, D, C, C, B, D, A,] studentExam = [ B, D, A, D, C, A, B, A, C, A, B, C, D, A, D, C, C, B, D, A,] index = 0 numCorrect = 0 for answerLine, studentLine in zip (answerKey, studentExam): answer = answerLine.split() studentAnswer = studentLine.split() if studentAnswer != answer: print( 'You got that question number', index + 1, 'wrong\n the correct,\ answer was' ,answer, 'but you answered' , studentAnswer) index += 1 else: numCorrect += 1 index += 1 grade = int((numCorrect / 20) * 100) print (' The number of correctly answered questions: ', numCorrect) print (' The number of incorrectly answered questions: ', 20 - numCorrect) print (' Your grade is', grade, '%') if grade &lt;= 75: print (' You have not passed ') else: print (' Congrats you have passed ') answerKey.close() studentExam.close() </code></pre> <hr> <pre><code># This program stores the correct answer for a test # then reads students answers from .txt file # after reading determines and dislpays pass or fail (15 correct to pass) # Displays number of correct and incorrect answers for student # then displays the number for the missed question/s #Creat the answer list def main ( ): # Create the answer key list key = [ B, D, A, A, C, A, B, A, C, D, B, C, D, A, D, C, C, B, D, A,] print (key) # Read the contents of the student_answers.txt and insert them into a list def read_student( ): # Open file for reading infile = open ( 'student_answers.txt', 'r' ) # Read the contents of the file into a list student = infile.readlines ( ) # Close file infile.close ( ) # Strip the \n from each element index = 0 while index &lt; len(student): student[index] = student[index].rstrip ( '\n' ) # Print the contents of the list print (student) # Determine pass or fail and display all results def pass_fail(answers, student): # Lists to be used to compile amount correct, # amount wrong, and questions number missed correct_list = [] wrong_list = [] missed_list = [] # For statement to compile lists for ai,bi in zip (key,student): if ai == bi: correct_list.append(ai) else: wrong_list.append(ai) missed_list.append(ai) # Printing results for user print(correct_list,' were answered correctly') print(wrong_list,' questions were missed') # If statement to determine pass or fail if len(correct_list) &gt;=15: print('Congrats you have passed') else: print('Sorry you have faild please study and try, \ again in 90 days') print('Any attempt to retake test before 90 days, \ will result in suspension of any licenses') # Displaying the question number for the incorrect answer print ( 'You missed questions number ', missed_list) main() </code></pre> <hr> <pre><code>a = (1, 'A'),(2,'C'),(3,'B') b = (1,'A'), (2,'A'),(3,'C') correct_list = [] wrong_list = [] missed_list = [] for ai, bi in zip (a, b): if ai == bi: correct_list.append(ai) else: wrong_list.append(ai) missed_list.append(ai) index(ai)+1 print(correct_list,'answered correct') print(wrong_list, 'answered wrong') if len(correct_list) &gt;=2: print ('Congrats you have passed') else: print ('Sorry you have faild please study and try again in 90 days') print('Any attempt to retake test before 90 days will result in suspension of any lisences') print ('Question number missed', missed_list) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload