title: drivers license test questions using python
body: <p>The local Driver's License Office has asked you to write a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1.A 2.C 3.A 4.A 5.D 6.B 7.C 8.A 9.C 10.B 11.A 12.D 13.C 14.A 15.D 16.C 17.B 18.B 19.D 20.A</p>
  
  <p>your program should store these correct answers in a list. The program should read the student's answers for each of the 20 questions from a text file and store the answers in another list. After the students's answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. The student must correctly answer 15 of the 20 questions to pass. It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.</p>
  
  <p>If anyone can give me some input on what I am doing wrong it would be greatly appreciated.</p>
  
  <pre><code>def main():
      corr_ans_list = ["A", "C", "A", "A", "D", "B",
                       "C", "A", "C", "B", "A", "D",
                       "C", "A", "D", "C", "B", "B",
                       "D", "A"]
      user_ans_list = []
      corr_count = 0
      incorr_count = 0
      num_questions = 20
  
      infile = open('user_answers.txt', 'r')
  
      user_ans_list = infile.readlines()
  
      infile.close()
  
      index = 0
  
      print("Q\tocrr\tYour\tStatus")
      print("#\tAnswer\tAnswer\n--------------------------")
  
      while index &lt; 20:                 
      print(str(index+1) + "\t" + corr_ans_list[index]+ "\t" + user_ans_list[index],end="\t" )
          if user_ans_list[index].strip() == corr_ans_list[index]:
              corr_count += 1
              index += 1
              print("               Correct")
          else:
              incorr_count += 1
              index += 1
              print("               Wrong")
  
      percent_corr = (corr_count/num_questions) * 100
      percent_corr_fmt = format(percent_corr, ".1f")
      print("Grade : ", corr_count , "/", num_questions, " = ",
            percent_corr_fmt, sep="")
  
      if percent_corr &gt;= 75:
          print("Congratulations!! You passed the exam")
      else:
          print("Sorry, you did not pass the exam")
  
  
  main()
  </code></pre>
  
  <p>The final answer I have gotten.</p>
  
  <pre><code>Q   Corr    Your    Status
  #   Answer  Answer
  --------------------------
  1   A   A
                     Correct
  2   C   C
                     Correct
  3   A   A
                     Correct
  4   A   B
                     Wrong
  5   D   D
                     Correct
  6   B   B
                     Correct
  7   C   C
                     Correct
  8   A   A
                     Correct
  9   C   C
                     Correct
  10  B   B
                     Correct
  11  A   B
                     Wrong
  12  D   D
                     Correct
  13  C   C
                     Correct
  14  A   A
                     Correct
  15  D   D
                     Correct
  16  C   B
                     Wrong
  17  B   B
                     Correct
  18  B   B
                     Correct
  19  D   B
                     Wrong
  20  A   A
                     Correct
  Grade : 16/20 = 80.0
  Congratulations!! You passed the exam
  </code></pre>