Code for PROGRAM TO EVALUATE A MULTIPLE-CHOICE TEST in Python Programming.
Write a program to check responses of a student to the multiple-choice exam in Python.
Python Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | answer_sheet ="abbddacdcbbdaccddbac" #correct answers test_answers = [None]*len(answer_sheet) #number of questions count=0 #Reading student responses and counting correct ones print("Answers can only be (a, b, c, d) \n") i=0 while i < len(test_answers): char = input("Input responses of student answer {0} :".format(i+1)) if char == "a" or char == "b" or char == "c" or char == "d": test_answers[i]=char i+=1 print("\n") for i in range(len(answer_sheet)): if answer_sheet[i] == test_answers[i]: count+=1 else: print("answer {0} is wrong".format(i+1)) print("Score is {} out of {}\n".format(count, len(answer_sheet))) |
Output:
Python Code: you can use this code for null value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | answer_sheet ="abbddacdcb" #correct answers test_answers = [None]*len(answer_sheet) #number of questions count=0 #Reading student responses and counting correct ones print("Answers can only be (a, b, c, d, null(n)) \n") i=0 while i < len(test_answers): char = input("Input responses of student answer {0} :".format(i+1)) if char == "a" or char == "b" or char == "c" or char == "d" or char == "n": test_answers[i]=char i+=1 print("\n") for i in range(len(answer_sheet)): if answer_sheet[i] == test_answers[i]: count+=1 else: print("answer {0} is wrong".format(i+1)) print("Score is {} out of {}\n".format(count, len(answer_sheet))) |