Computers and Technology, 11.10.2020 01:01 chonawilson4
#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).
Answers: 3
Computers and Technology, 23.06.2019 03:30, bellsbella34
Ihave a singular monitor that is a tv for my computer. recently, i took apart my computer and put it back together. when i put in the hdmi cord and booted the computer to see if it worked, the computer turned on fine but the screen was blue with "hdmi no signal." i've tried everything that doesn't require buying spare parts, any answer is appreciated!
Answers: 1
Computers and Technology, 24.06.2019 20:50, cookie1701
Which key function of a business involves finding, targeting, attracting, and connecting with the right customers?
Answers: 3
#Write a function called grade_scantron. grade_scantron should
#take as input two lists: answers an...
Chemistry, 14.01.2021 06:40
Biology, 14.01.2021 06:40
Mathematics, 14.01.2021 06:40
English, 14.01.2021 06:40
Biology, 14.01.2021 06:40
Biology, 14.01.2021 06:40