subject

#Write a function called grade_scantron. grade_scantron should #take as input two lists: answers and key. Each list contain
#strings. Each string will be only one letter, a character
#from A to E. grade_scantron should return how many questions
#the student got "right", where a student gets a question
#right if their answer for a problem matches the answer key.
#
#In other words, if value of the first item in answers matches
#the value of the first item in key, the student gets a point.
#If it does not, the student does not get a point.
#
#If the lists do not have the same number of items, return
#-1 to indicate that the answer key did not belong to the
#same test as the student's answers.\
#
#Hint: in the past, lots of people have tried to do this using
#the index() method. That won't work! You'll need to track the
#index yourself.

#Write your function here!
def grade_scantron(answers, key):
count=0
result=-1
try:
if len(key) != len(answers):
result=-1
except:
result=count
for index, item in enumerate(answers):
if(key[index] == answers[index]):
count+=1

return(result)

#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: 7
answers = ["A", "B", "B", "A", "D", "E", "B", "A","D"]
key = ["A", "B", "B", "A", "D", "E", "B", "A", "D"]
print(grade_scantron(answers, key))

I keep getting -1 and I don't know why. No matter what I do, I can't get the code to print either -1 (if the lengths don't match) or the amount of correct answers ( if the lengths do match up).

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:30
Auniversity wants to install a client-server network. which feature do you think is important for them as they set up the network? sending email blocking multiple people to use the same file low security low set up cost limited access to files
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
If joey was single and his taxable income was $9,500, how much would he pay in taxes each year?
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
Match the file formats with the types of multimedia they can store
Answers: 2
question
Computers and Technology, 24.06.2019 08:00
Can someone work out the answer as it comes up in one of my computer science exams and i don't understand the cryptovariables
Answers: 1
You know the right answer?
#Write a function called grade_scantron. grade_scantron should #take as input two lists: answers an...
Questions
question
Mathematics, 22.06.2020 18:57
question
Mathematics, 22.06.2020 19:57
question
Mathematics, 22.06.2020 19:57