Question

Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...

Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the original list). The second entry in the tuple should be the percent of the values in the list (excluding the weight value) that are non-negative.

6. Write a function named compute_grade that has two parameters, both dictionaries. The keys for the first dictionary are strings (grade categories) and the values are lists of numbers (category weights and scores, where -1 indicates an assignment that has not yet been graded). The second keys for the The second dictionary key values are letters and the values are tuples with the lowest and highest grade that would match the key letter grade. Your function should return a tuple with 3 values. The first value in the tuple is the total grade. This is computed as the grade out of the full 100% available for the semester. Ex: if the grades for all completed assignments have been 100%, then the returned value would be 100%. The second value in the tuple is the current grade. This is computed as the grade out of the work completed (for this calculation, you will need to use the percent of the work completed in each category). Ex: if only 60% of the class assignments have been completed and the grades for each assignment have been 100, then the returned value would be 60%. The third value in the tuple is the letter grade based on the current grade.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

AS PER CHEGG GUIDELINES ONLY ONE PROBLEM IS ALLOWED IN A QUESTION. ASK SEPARATE QUESTION FOR SECOND PROBLEM.

Code:

#This function has one parameter, a dictionary.
#The keys for the dictionary are strings and the values are lists of numbers.
def grade_components(data):
result={} #New dictionary that will hold results
#looping for every key value pair
for key in data:
listOfValues=data[key] #getting list of values for the current key
weight=listOfValues[0] #getting weight which is the first value
listOfValues.pop(0) #removing wieght from the list
positives=0 #initially positives are zero
total=0 #total number in list are also zero
weightedAverage=0 # initializing weightedAverage to zero
for value in listOfValues: #looping for each value in list
if value>=0: #if value is greater than or equal to 0 then taking it as positive
positives=positives+1 #incrementing positives
weightedAverage=weightedAverage+weight*value #adding weight*value to weighted average
total=total+1 #incrementing total
weightedAverage=weightedAverage/(positives*weight)#calculating weighted average
result[key]={weightedAverage,(positives/total)*100} #setting tuple for the key in new dictionary.First value is average weighted key and second is percentage of positive values
return result #returning result


data={"stud1":[100,48,66,-97,78],"stud2":[50,45,-47,37]}
print(grade_components(data))

Code screenshot:

Output:

Add a comment
Know the answer?
Add Answer to:
Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...
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
  • Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys)...

    Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary ("puffin": 5, "corgi": 2, "three": 3) and the list ("three", "corgi"), your function should return {"corgi": 2, "three"...

  • write a function firstLetterWords(words) that takes as a parameter a list of strings named words and...

    write a function firstLetterWords(words) that takes as a parameter a list of strings named words and returns a dictionary with lower case letters as keys. But now associate with each key the list of the words in words that begin with that letter. For example, if the list is ['ant', 'bee', 'armadillo', 'dog', 'cat'], then your function should return the dictionary {'a': ['ant', 'armadillo'], 'b': ['bee'], 'c': ['cat'], 'd': ['dog']}.

  • in python Write a program that keeps a dictionary in which both keys and values are...

    in python Write a program that keeps a dictionary in which both keys and values are strings—names of students and their course grades. Prompt the user of the program to add or remove students, to modify grades, or to print all grades. The printout should be sorted by name and formatted like this: Carl: B- Joe: C Sarah: A Francine: A

  • Define a Python function named borough_count that has one parameter. The parameter is a string representing...

    Define a Python function named borough_count that has one parameter. The parameter is a string representing the name of a CSV file. The CSV file is a subset of NYC's dataset of all film permits issued since April 2016. Each row in the CSV file has the format: Event Id, Police Precinct(s), Event Type, Borough, Category Your function must return a dictionary. The keys of this dictionary will be the boroughs read in from the file (boroughs are at index...

  • project-8a Write a function named count_letters that takes as a parameter a string and returns a...

    project-8a Write a function named count_letters that takes as a parameter a string and returns a dictionary that tabulates how many of each letter is in that string. The string can contain characters other than letters, but only the letters should be counted. The string could even be the empty string. Lower-case and upper-case versions of a letter should be part of the same count. The keys of the dictionary should be the upper-case letters. If a letter does not...

  • Python 3 Write a function named inverse that takes a single parameter, a dictionary. In this...

    Python 3 Write a function named inverse that takes a single parameter, a dictionary. In this dictionary each key is a student, represented by a string. The value of each key is a list of courses, each represented by a string, in which the student is enrolled. The function inverse should compute and return a dictionary in which each key is a course and the associated value is a list of students enrolled in that course. For example, the following...

  • USING PYTHON! a) Programmatically (do not just write a definition!) create a dictionary whose keys are...

    USING PYTHON! a) Programmatically (do not just write a definition!) create a dictionary whose keys are the integers 1 through 10 and whose respective values are the keys cubed (e.g. a key of 5 has a value of 125). b) Write a function that, given a user inputted string, outputs a dictionary where each letter is a key and each value is the letter’s position in the string. Note that you ​must handle cases where a word could contain the...

  • PYTHON Define the remove_e_synonyms() function which is passed a dictionary as a parameter. The keys of...

    PYTHON Define the remove_e_synonyms() function which is passed a dictionary as a parameter. The keys of the parameter dictionary are words and the corresponding values are lists of synonyms (synonyms are words which have the same or nearly the same meaning). The function removes all the synonyms which contain the letter 'e' or 'E') from each corresponding list of synonyms. As well, the function sorts each corresponding list of synonyms. Note: the testing code makes use of the print_dict_in_key_order(a_dict) which...

  • Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description:...

    Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...

  • Write a function called, sameKeys, that takes in two dictionaries. The sameKeys function looks for keys...

    Write a function called, sameKeys, that takes in two dictionaries. The sameKeys function looks for keys that are found in both dictionaries and returns a new dictionary that contains key:value pairs where the key in the new dictionary is the key found in both dictionaries, dictionl and diction2, and the new key's value being a list of the values of dictionl.key and diction2.key values concatenated together. Assumptions 1) 2) Both dictionaries can be empty and an empty dictionary is returned...

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