Need some assistance with this. This is in python. functions with lists and tupl
ID: 3729773 • Letter: N
Question
Need some assistance with this. This is in python.
functions with lists and tuples You are to create a program that will aid in grading a multiple choice assessment that contains 20 questions. Your program will compare the answers from a student to the correct answers and determine if the student answered at least 75% of the questions correctly to pass the assessment. Your program will also provide an output listing the correct answers, the student's answers, and whether the student's answers were correct. The answers will be upper case letters A through E and you may assume the student answered all 20 questions Your program should employ 3 functions other than main (which will act as a driver for the other functions). The first of these 3 functions should be used to input the student's answers. This function should not accept any parameters and will return a list containing upper case characters for the student's answers. Inside this function use a loop to prompt the user to enter the student's responses to the 20 questions one at a time and stored the student's responses in a list. You may assume that the user will input an appropriate upper case character for the student's response. Once the loop is finished, the list of student's responses should be returned to the function call. The second of these functions will compare the student's answers to the correct answers and count how many answers are correct. This function should accept 2 parameters (a tuple of correct answers and the list of student's answers), and will return the string "Passed" when the student answers at least 15 questions correctly. When the student answers fewer than 15 questions correctly, the string "Failed" should be returned. A loop should be used to count the number of questions the student answered correctly and should be returned to the function call along with the string. Note two items are being returned to the function call: the string indicating that the student passed or failed and the number of questions the student answered correctly The third function will output the correct answers, the student's answers and whether the student's answers were correct in table. This function should accept two parameters (the tuple of correct answers and the list of student's answers) and will not return anything to the function call. Using a loop the function should output the question number, the correct answer, theExplanation / Answer
Please find the code in python 3 as per the requirement. The comments have been presented thoroughly.
In case of any further equirement, please comment.
Hope this helps! If it works, please thumbs up!
#=======================================================================================================
def read_resp(): # Function for recording Student Responses
resp={}; # Creating an empty list for storing student responses
for i in range(0,20): # Looping for recording the input
resp[i]=input('Please input the answer for question no.'+str(i+1)+' :');
return resp;
def eval_resp(std_ans,crct_ans): # Function for evaluating the student's fail/pass status and score
score=0; # Initialzing score count variable
evaltn={}; # Creating an emply list that will store the student's score and status to be returned as a single vaariable
for i in range(0,20): # Looping to compare the student's reponses with correct answers
if(std_ans[i]==crct_ans[i]):
score=score+1; # Counting the number of correct answers
evaltn['score']=score; # Storing the score value in the list
if (score < 15):
evaltn['status']='Failed'; # Storing status as 'Failed' when less than 15 questions were correctly answered
else:
evaltn['status']='Passed'; # Storing status as 'Passed' when atleast 15 questions were correctly answered
return evaltn; # Returning the resulting score and evaluation status
def summary(crct_ans,std_ans): # Function to display the question vise evaluation of student's answers
for i in range(0,20):
if(crct_ans[i]==std_ans[i]): # Looping to compare the student's input with correct answers and displaying the corresponding output as per the requirement
print('Question: '+str(i+1)+' Expected Answer: '+crct_ans[i]+' Student's Answer: '+std_ans[i]+' Correct');
else:
print('Question: '+str(i+1)+' Expected Answer: '+crct_ans[i]+' Student's Answer: '+std_ans[i]+' Incorrect');
return;
#=======================================================================================
#==================================== Main Function ====================================
#=======================================================================================
# Tuple to store the correct answers to the questions
crct_ans = ('A','B','C','D','E','A','B','C','D','E','A','B','C','D','E','A','B','C','D','E');
# Storing the student's responses in 'std_ans' list by calling the 'read_resp' function
std_ans=read_resp();
# Storing the student's evaluated score and status in 'evaltn' list by calling the 'eval_resp' function
evaltn=eval_resp(std_ans,crct_ans);
# Displaying the question vise evaluation of student's answers as per the requirement by calling 'summary' function
summary(crct_ans,std_ans);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.