Question

def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in...

def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float:
"""Return the average number of clubs that a person in person_to_clubs
belongs to.

>>> get_average_club_count(P2C)
1.6
>>> get_average_club_count({'Bob': ['X', 'Y'], 'John': []})
1.0
"""

This is the function I need to test for edge cases, I need to have a test case such that it will detect that the input has been modified(mutation). What test case would I implement?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def get_average_club_count(person_to_clubs) -> float:
    total = 0
    for x in person_to_clubs.keys():
        total+=len(person_to_clubs[x])
    return total/len(person_to_clubs.keys())

# Testing
print(get_average_club_count({'Bob': ['X', 'Y'], 'John': []}))

Add a comment
Know the answer?
Add Answer to:
def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in...
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
  • def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data...

    def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data dict, and the current location ID, get all the possible actions at that location. If the decision number given as 'decision' falls outside the number of allowed actions at this location, then return the string "Invalid decision. Please select choice from the decisions listed." Make sure this string is EXACTLY as above. Else, if the decision is valid, then figure out the location information...

  • I am practicing python by doing some projects, and I am stuck on this function. I'd...

    I am practicing python by doing some projects, and I am stuck on this function. I'd like to know how to do it without using statements like break, input, print, or continue. The first parameter represents a "person to friends" dictionary, the second parameter represents a "person to clubs" dictionary, and the third parameter represents a person's name in the same format as the dictionary keys). Using the recommendation system described below, the function should return the club recommendations for...

  • Question 4a (2 points): Finding Edge Cases I This program is a partially correct solution to...

    Question 4a (2 points): Finding Edge Cases I This program is a partially correct solution to the winning streak problem from a previous lab. Given a string, list, or tuple as input, find the longest winning streak. This solution contains an error. Find a test case that returns an incorrect value, or raises an error Do not modify or try to correct the code for this question, simply find a problematic input for the function # Modify the value of...

  • The code: def isPalindrome(text): """ >>> isPalindrome("alula") True...

    The code: def isPalindrome(text): """ >>> isPalindrome("alula") True >>> isPalindrome("love") False >>> isPalindrome("Madam") True >>> isPalindrome(12.5) False >>> isPalindrome(12.21) False >>> isPalindrome("Cigar? Toss it in a can.! It is so tragic.") True >>> isPalindrome("travel.. a town in Alaska") False """ # --- YOU CODE STARTS HERE if type(text) is not str: return False l = len(text) - 1 i = 0 while i < l: if text[i] in string.punctuation or text[i] == ' ': i += 1 elif text[l] in...

  • Implement a program that: reads a number of personal records (for example, using PERSON struct from...

    Implement a program that: reads a number of personal records (for example, using PERSON struct from the earlier lab) from the standard input, creates a database of personal records, allows for adding new entries to the database, allows for deleting entries from the database, includes functions to acquire a record of personal data, and includes functions to display (print) a single selected record from the database, and also allows for printing all records in the database. NOTES: if name is...

  • Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user...

    Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...

  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

  • THIS IS WHAT I HAVE I NEED TO FIX IT SO: hours_worked should not be inputed...

    THIS IS WHAT I HAVE I NEED TO FIX IT SO: hours_worked should not be inputed separately. Get the hours as 40 40 40 40 or 40, 40, 40, 40 whichever separator suits you. How do I do this? How would you change what I have in to it getting into that kind of input. Thank you! class Employee: again = 'y' def __init__(self): self.__rate = 7.25 self.__totalhour = 0 self.__regularpay = 0 self.__overtimepay = 0 self.__totalpay = 0 self.__tax...

  • Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Plea...

    Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the...

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