Question: Question: Test the function by_origins from a created module named t0.py and record it in testing.txt -------------------------------------------------------------------------------------------------------------- Food_utilities.py from Food import Food def by_origin(foods, origin):

Question:

Test the function by_origins from a created module named t0.py and record it in testing.txt

--------------------------------------------------------------------------------------------------------------

Food_utilities.py

from Food import Food

def by_origin(foods, origin): """ ------------------------------------------------------- Creates a list of foods by origin. foods is unchanged. Use: v = by_origin(foods, origin) ------------------------------------------------------- Parameters: foods - a list of Food objects (list of Food) origin - a food origin (int) Returns: origins - Food objects from foods that are of a particular origin (list of Food) ------------------------------------------------------- """ assert origin in range(len(Food.ORIGIN)) Food.origins() origins = [] for i in range(0,len(foods)): if foods[i].origin == origin: origins.append(foods[i]) return origins

--------------------------------------------------------------------------------------------------------------

Food.py

class Food: """ Defines an object for a single food: name, origin, vegetarian, calories. """ # Constants ORIGIN = ("Canadian", "Chinese", "Indian", "Ethiopian", "Mexican", "Greek", "Japanese", "Italian", "American", "Scottish", "New Zealand", "English")

@staticmethod def origins(): """ ------------------------------------------------------- Creates a string list of food origins in the format: 0 Canadian 1 Chinese 2 Indian ... Use: s = Food.origins() Use: print(Food.origins()) ------------------------------------------------------- Returns: string - A numbered list of valid food origins (str) ------------------------------------------------------- """

string = "" for i in range (len(Food.ORIGIN)): string += """{:2d} {} """.format(i, Food.ORIGIN[i])

return string

---------------------------------------------------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!