85.1k views
2 votes
#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).

User Pablito
by
7.7k points

1 Answer

4 votes

En este ejemplo vemos que, por la información dada, no es posible que esta oración tenga coherencia o sentido. En este caso el nexo o conector que une ambas oraciones no debería haberse utilizado, puesto que ambas oraciones no tienen relación. Por ende corresponden a estructuras diferentes y no es posible que mantengan una coherencia. Varias oraciones sin coherencia, generan textos incoherentes.

User Tomloprod
by
8.4k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.