Professional Documents
Culture Documents
CS 115 - Introduction To Programming in Python Lab Guide 09: Lab Objectives: Searching and Sorting
CS 115 - Introduction To Programming in Python Lab Guide 09: Lab Objectives: Searching and Sorting
Lab Guide 09
iv. Add a __repr__ method to return the string representation of an Order. See
sample run for format.
b. Write a the following functions in python file, Lab09.py :
i. load_orders (): function takes a filename as a parameter. The function
should read the data from the file, create Orders from the file and add them to a
list. Return the list of Orders. Read and understand the data in the file and the
functionality provided in the Order class to create the orders.
ii. get_orders_by_price (): takes a list of Orders, a minimum value and a
maximum value as parameters. The function should search the list and return ALL
orders whose total price is between the minimum and maximum value.
c. Write a script that does the following:
i. Load a list of Orders with data from the file order_list.txt. The file is
whitespace delimited.
ii. Display the list of Orders.
iii. Sort and display the list of Orders by their delivery dates in ascending order.
iv. For each Order in the list, sort the items by name. (use functionality defined in the
Order class).
v. Input a minimum and maximum price and display all orders whose total is between
the min and max.
vi. Input an item to search, and for the first Order in the list, display the information
(name and price) of the item.
Sample Run:
Orders:
[
Johnson Mark 2021-09-18 [('bananas', 10.96), ('apples', 2.5), ('milk', 3.95)] Total: 17.41,
Kirkdal Shirley 2021-12-16 [('oranges', 5.96), ('apples', 2.5), ('tea', 7.95)] Total: 16.41,
Mackie Inaayah 2021-09-05 [('pears', 2.96), ('apples', 2.5), ('milk', 3.95)] Total: 9.41,
Freeman Keenan 2021-12-20 [('watermelon', 15.96), ('apples', 2.5), ('milk', 3.95)] Total: 22.41,
Woolley Janine 2021-05-30 [('oranges', 5.96), ('apples', 2.5), ('milk', 3.95)] Total: 12.41,
Michael Eadie 2021-12-19 [('chicken_breast', 25.96), ('apples', 2.5), ('milk', 3.95)] Total: 32.41,
Dermott Kris 2021-12-18 [('bread', 3.5), ('apples', 2.5), ('milk', 3.95)] Total: 9.95,
Terrell Melvin 2021-11-22 [('mozzarella', 15.45), ('potatoes', 2.5), ('milk', 3.95)] Total: 21.90,
Allison Naeem 2021-09-07 [('tomatoes', 8.95), ('parsley', 1.5), ('coffee', 45.95)] Total: 56.40,
Johnson Trey 2021-02-21 [('oranges', 5.96), ('apples', 2.5), ('milk', 3.95)] Total: 12.41,
Plummer Elana 2021-12-17 [('spaghetti', 10.0), ('zucchini', 8.5), ('parmesan', 73.95)] Total: 92.45,
Allison Joelle 2021-09-18 [('sparkling_water', 8.95), ('lime', 12.5), ('oranges', 3.95)] Total: 25.40,
Smither Sandy 2021-12-17 [('tuna', 25.5), ('pickles', 8.5), ('white_cheese', 13.25)] Total: 47.25]
Orders by Date:
[
Johnson Trey 2021-02-21 [('oranges', 5.96), ('apples', 2.5), ('milk', 3.95)] Total: 12.41,
Woolley Janine 2021-05-30 [('oranges', 5.96), ('apples', 2.5), ('milk', 3.95)] Total: 12.41,
Mackie Inaayah 2021-09-05 [('pears', 2.96), ('apples', 2.5), ('milk', 3.95)] Total: 9.41,
Allison Naeem 2021-09-07 [('tomatoes', 8.95), ('parsley', 1.5), ('coffee', 45.95)] Total: 56.40,
Johnson Mark 2021-09-18 [('bananas', 10.96), ('apples', 2.5), ('milk', 3.95)] Total: 17.41,
Allison Joelle 2021-09-18 [('sparkling_water', 8.95), ('lime', 12.5), ('oranges', 3.95)] Total: 25.40,
Terrell Melvin 2021-11-22 [('mozzarella', 15.45), ('potatoes', 2.5), ('milk', 3.95)] Total: 21.90,
Kirkdal Shirley 2021-12-16 [('oranges', 5.96), ('apples', 2.5), ('tea', 7.95)] Total: 16.41,
Plummer Elana 2021-12-17 [('spaghetti', 10.0), ('zucchini', 8.5), ('parmesan', 73.95)] Total: 92.45,
Smither Sandy 2021-12-17 [('tuna', 25.5), ('pickles', 8.5), ('white_cheese', 13.25)] Total: 47.25,
Dermott Kris 2021-12-18 [('bread', 3.5), ('apples', 2.5), ('milk', 3.95)] Total: 9.95,
Michael Eadie 2021-12-19 [('chicken_breast', 25.96), ('apples', 2.5), ('milk', 3.95)] Total: 32.41,
Freeman Keenan 2021-12-20 [('watermelon', 15.96), ('apples', 2.5), ('milk', 3.95)] Total: 22.41]