Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

What is a performance baseline?

Answered: 1 week ago