CODING 2 [10 pts] – The animals are ready to PARTAY! Write a…
CODING 2 [10 pts] – The animals are ready to PARTAY! Write a function called partyAnimals() that takes in 2 lists, animalList and animalDiet. animalList is a list of animal names representing the guests, and animalDiet is the corresponding dish they would like to bring. Return a dictionary partyDict that maps each animal’s name to the dish they will bring, only if the dish starts with the same first two letters as the animal’s name (case-insensitive), and the dish is not another animal guest. Note: animalList and animalDiet are the same length, and each animal appears only once in animalList. Example #1: >>> animalList = [“Chimpanzees”, “Toucans”, “Butterflies”, “Worms”] >>> animalDiet = [“chips”, “worms”, “Butter cookies”, “Organic Matter”] >>> partyAnimals(animalList, animalDiet)Expected Output #1: {‘Chimpanzees’: ‘chips’, ‘Butterflies’: ‘Butter cookies’} Example #2: >>> animalList = [“Shark”, “Bass”, “Shrimp”, “Squid”] >>> animalDiet = [“shrimp”, “BANANAS”, “krill”, “Scallion pancakes”] >>> partyAnimals(animalList, animalDiet) Expected Output #2:{‘Bass’: ‘BANANAS’}
Read DetailsChoose the code segment that, when included in the indicated…
Choose the code segment that, when included in the indicated place within the sortedVowels() function, will result in the function correctly returning a list of the unique sorted vowels contained in the parameter aStr and doing so in the most efficient way. def sortedVowels(aStr): vowels = “aeiou” outlist = [] [ CODE GOES HERE ] return outlist
Read DetailsThe following function has been implemented to request a lis…
The following function has been implemented to request a list of values from a user and calculate their average; however, it errors for specific inputs. What test cases reveal the limitations of the current implementation? def computeAvg(): values = input(“Provide a set of values separated by spaces:”) listVal = values.split(” “) total = 0 count = len(listVal) for val in listVal: total += int(val) average = total/count print(f”The average is {average}.”) “13 67 01” “12.1 100 23” “5 6 10 8 11” “”
Read DetailsYou are a rainforest ranger in the Amazon. To understand the…
You are a rainforest ranger in the Amazon. To understand the biodiversity of the rainforest, you plan to record how many of each animal there are. You hope to use a data structure that allows you to store count of each animal along with its name in sorted order from the most frequent to the least. Which data structure is most suitable?
Read Details