Computers and Technology

#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).

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:00, vane1161
Aletter or menu command that starts an action when the user presses the designated letter and the alt key together is called what?
Answers: 1
image
Computers and Technology, 22.06.2019 11:30, KrishnaBalaram1235
To hide gridline when you display or print a worksheet
Answers: 1
image
Computers and Technology, 22.06.2019 19:20, SundaeSunday
Consider the following code snippet: #ifndef cashregister_h#define cashregister_hconst double max_balance = 6000000.0; class cashregister{public: cashregister(); cashregister(double new_balance); void set_balance(double new_balance); double get_balance() const; private: double balance[12]; }; double get_monthly_balance(cashregister bk, int month); #endifwhich of the following is correct? a)the header file is correct as given. b)the definition of max_balance should be removed since header files should not contain constants. c)the definition of cashregister should be removed since header files should not contain class definitions. d)the body of the get_monthly_balance function should be added to the header file.
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, med69
Barbara is interested in pursuing a career in the science and math pathway. which qualifications will her reach that goal? a. an advanced knowledge of physics and math b. an advanced knowledge of engineering and math c. an advanced knowledge of physics and robotics an d. advanced knowledge of machinery and math
Answers: 2
Do you know the correct answer?
#Write a function called grade_scantron. grade_scantron should #take as input two lists: answers an...

Questions in other subjects:

Konu
Mathematics, 01.10.2019 02:00
Konu
English, 01.10.2019 02:00