Question

Create a new program in Mu and save it as ps4.3.1.py and take the code below...

  1. Create a new program in Mu and save it as ps4.3.1.py and take the code below and fix it as indicated in the comments:

    # 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!
    
    # 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
    test_answers = ["A", "B", "B", "A", "D", "A", "B", "A", "E"]
    test_key = ["A", "B", "B", "A", "D", "E", "B", "A", "D"]
    print(grade_scantron(test_answers, test_key))
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please comment if you have any doubt

Code:

def grade_scantron(answers, key):
'''function to calculate grade'''
#if the lists len is not same return -1
if(len(answers)!=len(key)):
return -1
#count of matches of answer with key
count=0
for i in range(len(answers)):
#if answer in a position with matches key
#then count is incremented
if(answers[i]==key[i]):
count+=1
#return total score
return count

test_answers = ["A", "B", "B", "A", "D", "A", "B", "A", "E"]
test_key = ["A", "B", "B", "A", "D", "E", "B", "A", "D"]
print(grade_scantron(test_answers, test_key))

def grade_scantron (answers, key) : function to calculate grade!!! #if the lists len is not same return -1 if(len (answers Output:

7

Add a comment
Know the answer?
Add Answer to:
Create a new program in Mu and save it as ps4.3.1.py and take the code below...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a new program in Mu and save it as ps4.5.2.py and take the code below...

    Create a new program in Mu and save it as ps4.5.2.py and take the code below and fix it as indicated in the comments: # Do not change the line of code below. It's at the top of # the file to ensure that it runs before any of your code. # You will be able to access french_dict from inside your # function. french_dict = {"me": "moi", "hello": "bonjour", "goodbye": "au revoir", "cat": "chat", "dog": "chien", "and": "et"} #...

  • Create a new program in Mu and save it as ps4.5.1.py and take the code below...

    Create a new program in Mu and save it as ps4.5.1.py and take the code below and fix it as indicated in the comments: # Write a function called phonebook that takes two lists as # input: # # - names, a list of names as strings # - numbers, a list of phone numbers as strings # # phonebook() should take these two lists and create a # dictionary that maps each name to its phone number. For #...

  • Create a new program in Mu and save it as ps4.2.2.py and take the code below...

    Create a new program in Mu and save it as ps4.2.2.py and take the code below and fix it as indicated in the comments: # Write a function called "in_parentheses" that accepts a # single argument, a string representing a sentence that # contains some words in parentheses. Your function should # return the contents of the parentheses. # # For example: # in_parentheses("This is a sentence (words!)") -> "words!" # # If no text appears in parentheses, return an...

  • Create a new program in Mu and save it as ps4.2.1.py and take the code below...

    Create a new program in Mu and save it as ps4.2.1.py and take the code below and fix it as indicated in the comments: # Write function called third_character that accepts a # string as an argument and returns the third character # of the string. If the user inputs a string with fewer than # 3 characters, return "Too short". # Write your function here! # Below are some lines of code that will test your function. # You...

  • Create a new program in Mu and save it as ps4.5.3.py and take the code below...

    Create a new program in Mu and save it as ps4.5.3.py and take the code below and fix it as indicated in the comments: # In the Pokemon video game series, every Pokemon has six # stats: HP, Attack, Defense, Special Attack, Special Defense, # and Speed. # # Write a function called total_stats that will take as input # a list of dictionaries. Each dictionary will have seven # key-value pairs: # # - name: a Pokemon's name #...

  • Create a new program in Mu and save it as ps4.3.2.py and take the code below...

    Create a new program in Mu and save it as ps4.3.2.py and take the code below and fix it as indicated in the comments: # Write a function called find_max_sales. find_max_sales will # have one parameter: a list of tuples. Each tuple in the # list will have two items: a string and an integer. The # string will represent the name of a movie, and the integer # will represent that movie's total ticket sales (in millions # of...

  • Create a new program in Mu and save it as ps3.4.2.py and take the code below...

    Create a new program in Mu and save it as ps3.4.2.py and take the code below and fix it as indicated in the comments: # A year is considered a leap year if it abides by the # following rules: # # - Every 4th year IS a leap year, EXCEPT... # - Every 100th year is NOT a leap year, EXCEPT... # - Every 400th year IS a leap year. # # This starts at year 0. For example:...

  • Create a new program in Mu and save it as ps3.4.3.py and take the code below...

    Create a new program in Mu and save it as ps3.4.3.py and take the code below and fix it as indicated in the comments: # Consult this blood pressures chart: http://bit.ly/2CloACs # # Write a function called check_blood_pressure that takes two # parameters: a systolic blood pressure and a diastolic blood # pressure, in that order. Your function should return "Low", # "Ideal", "Pre-high", or "High" -- whichever corresponds to # the given systolic and diastolic blood pressure. # #...

  • Create a new program in Mu and save it as ps4.4.1.py and take the code below...

    Create a new program in Mu and save it as ps4.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called "save_leaderboard" that accepts a # single list of tuples as a parameter. The tuples are of the # form (leader_name, score) # The function should open a file called "leaderboard.txt", # and write each of the tuples in the list to a line in the file. # The name and score...

  • Create a new program in Mu and save it as ps3.4.1.py and take the code below...

    Create a new program in Mu and save it as ps3.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called hide_and_seek. The function should # have no parameters and return no value; instead, when # called, it should just print the numbers from 1 through 10, # follow by the text "Ready or not, here I come!". Each # number and the message at the end should be on its own...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT