Question: In Python, A local college has asked you to create a Python program which will grade a certain portion of the final. The final has

In Python, A local college has asked you to create a Python program which will grade a certain portion of the final. The final has 25 questions where the answer is either, A,B,C or D. Here are the correct answers:

A

D

C

B

A

A

D

C

B

A

A

D

C

B

A

A

D

C

B

A

C

D

D

D

D

You program will need to store these correct answers in a list. Also, your program should read from a text file called student_answers.txt the students answers for each of the 5 questions and place the students answers in another list. After grading the final the program needs to display, the percentage correct and a letter grade which can be found in the grading scale below. It should then display the total number of correct answered questions, the total number of incorrectly answered questions and a list showing the question number of the incorrectly answered questions.

Finalple Output

Percentage Correct

88%

Letter Grade

B

You incorrectly answered

3 questions

You correctly answered

22 questions

You missed question numbers

1,5,12

Grading Scale

Test Score

Grade

>=90% and above

A

>=80% and <90%

B

>=70% and <80%

C

>=60% and <70%

D

<60% and below

F

The program should contain at least 3 functions, one for input (which should be called main), one for processing and one for output. The data will need to pass from main into your processing function and from the processing function to the output function.

Here is what I have:

def main(): correct_answers = ['A','D','C','B','A','A','D','C','B','A','A','D','C','B','A','A','D','C','B','A','C','D','D','D','D'] student_answers = [] with open("student_answers.txt","r") as ins: for line in ins: student_answers.append(line.rstrip(' ')) processing(correct_answers,student_answers) def processing(correct_answers,student_answers): correct = 0 wrong = 0 missed = [] for i in range(len(correct_answers)): if(correct_answers[i]==student_answers[i]): correct +=1 elif(student_answers[i]==""): missed.append(i+1) else: wrong +=1 percentage = (correct/len(correct_answers))*100 output(correct,wrong,missed,percentage) def output(correct,wrong,missed,percentage): print("persentage correct %d%%" %(percentage)) if(percentage>=90): print("Letter Grade A") elif(percentage < 90 and percentage >= 80): print("Letter Grade B") elif(percentage < 80 and percentage >= 70): print("Letter Grade C") elif(percentage < 70 and percentage >= 60): print("Letter Grade D") else: print("Letter Grade F") print("You incorrectly answered %d questions" %(wrong)) print("You correctly answered %d questions" %(correct)) if len(missed) == 0: print("you missed question numbers 0") else: print("you missed question numbers " + (",".join(map(str,missed)))) if __name__ == '__main': main()

and I am getting this error:

Traceback (most recent call last): File "C:\Users\Orna\Desktop\Shearin_FinalProject.py", line 6, in student_answers.append(line.rstrip(' ')) NameError: name 'student_answers' is not defined

Can anyone help me figure what I have done wrong?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!