Question: Python 3 fix all errors please: # Read from a file containing Predator-Prey #relationships, create a dictionary that contains every predator as values and #their
Python 3 fix all errors please:
# Read from a file containing Predator-Prey #relationships, create a dictionary that contains every predator as values and #their prey as a list of values. Using this dictionary, find Apex Predators, find #producers, identify most flexible eaters, identify "tastiest organism", and #determine the height of each organism in the food web. Print every identified item.
import sys
#whatPredatorsEat: Read every line in a given file and identify the preators and prey #Add them to a dictionary containing predator-prey relationships. # @param file - the file from which the function reads predator-prey relationships from
def whatPredatorsEat(file): print(" ") #Empty dictionary to be filled with predator-prey relationships relationship = {} #open file try: inf = open(file, "r") except IOError: print("Failed to open", file, ". Quitting...") quit() #for every line in the file, split the line into its elements by "eats" for line in inf: line = line.rstrip() element = line.split(" eats ") #if predator already in dictionary, add prey to list. #otherwise, add predator to list if(element[0] in relationship: relationship[element[0]].append(element[1]) else: relationship[element[0]] = [element[1]] inf.close() return relationship # printFriendlyString - takes dictionary containing pred-prey relationships, # prints in the correct format, "predator eats" followed by its list of prey. # @param relationship- dictionary of pred-prey relationships
def printFriendlyString(relationship): print("Predators and Prey: ") for key, value in relationship.items(): predEats = " " + str(key) + " eats" if len(value) == 1: predEats = str(predEats) + str(value[0]) else: for i in range(0, len(value)): if i
def printProducer(relationship): print(" ") print("The producers are: ") preys = [] for pred in relationship: for prey in relationship[pred]: if prey not in preys: preys.append(prey) for prey in preys: if prey not in relationship: print(" " + str(prey))
# printFlexible - Identifies which predators in the predator prey relationship # dictionary eats the greatest number of organisms (which value has the longest list # of values) and prints them. def printFlexible(relationship): print(" ") print("The most flexible eater is: ") max len = 0 max key = " " for key in relationship: flexible = len(relationship([key]) if flexible > max len: max len = flexible for key in relationship.keys(): if len(relationship[key]) == max len: print(" " + str(key)) # printTasty - Identifies which prey is eaten by the most different members of the foodchain # or which value appears most often in the list of values and prints them # @param - relationship- dictionary of pred-prey relationships def printTasty(relationship): print(" ") print("The Tastiest Prey is: ") tastiest = {} for prey in relationship: for preys in relationship[prey]: if preys in tastiest.keys(): tastiest[preys] = tasiest[preys] + 1 else: tastiest[preys] = 1
yum = [] tasty = 0 for i in tastiest: if tasty == tastiest[i]: tasty = tastiest[i] yum.append[i] elif tasty
# printHeights - Identified the longest path from an organism to a producer. # Lists height for every organism # @param - relationship- dictionary of pred-prey relationships def printHeights(relationship) print(" ") print("Heights: ") heights = {} allAnimals = set() for pred in relationship: allAnimals.add(pred) for prey in relationship[pred]: allAnimals.add(prey) for i in allAnimals: heights[i] = 0 eating = True while eating == True: eating = False for animal in relationship: for prey in relationship[animal]: if heights[animal]
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ OUTPUT SHOULD BE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Predators and Prey: Bird eats Crab, Limpets, Mussels, Prawn and Whelk Crab eats Limpets and Mussels Fish eats Prawn Limpets eats Seaweed Lobster eats Crab, Limpets, Mussels and Whelk Mussels eats Phytoplankton and Zooplankton Prawn eats Zooplankton Whelk eats Limpets and Mussels Zooplankton eats Phytoplankton Apex Predators: Bird, Fish and Lobster Producers: Phytoplankton and Seaweed Most Flexible Eaters: Bird Tastiest: Limpets and Mussels Heights: Bird: 4 Crab: 3 Fish: 3 Limpets: 1 Lobster: 4 Mussels: 2 Phytoplankton: 0 Prawn: 2 Seaweed: 0 Whelk: 3 Zooplankton: 1
======================
ERROR THAT OCCURS:
File "ass33.py", line 29 for line in inf: ^ IndentationError: unindent does not match any outer indentation level
CSV:

Mussels Crab Limpets Whelk Prawn Mussels Limpets Prawn Bird 2 Crab 3 Fish 4 Limpets Seaweed 5 Lobster 6 Mussels Phytoplankte Zooplankton 7 Prawrn 8 Whelk Crab Mussels impets Whelk Zooplankton Limpets Mussels Mussels Act 9 Zooplankton PhytoplanktonAquaticFoodWeb.csv 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
