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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started