Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me solve this Python code? Thank you: An online clothing store product filtering program. The program receives input about product type and

Can someone help me solve this Python code? Thank you:

"""An online clothing store product filtering program.

The program receives input about product type and

the filter type - max or range - as well as one or

two prices depending on the filter type.

The program performs the filter and displays a list

of matching products back to the user

"""

# Online clothing store catalog of know products

CATALOG = [

{"product_name": "long sleeve polo", "type": "shirts", "price": 22.60},

{"product_name": "dobby dress shirt", "type": "shirts", "price": 29.49},

{"product_name": "stripe rugby shirt", "type": "shirts", "price": 39.49},

{"product_name": "irving button-up shirt", "type": "shirts", "price": 19.99},

{"product_name": "performance polo", "type": "shirts", "price": 26.59},

{"product_name": "cotton pique polo", "type": "shirts", "price": 42.15},

{"product_name": "stretch flannel shirt", "type": "shirts", "price": 46.25},

{"product_name": "slim fit pocket joggers", "type": "pants", "price": 45.99},

{"product_name": "microcheck wool pants", "type": "pants", "price": 76.95},

{"product_name": "pocket training pants", "type": "pants", "price": 56.69},

{"product_name": "polar fleece sweatpants", "type": "pants", "price": 49.99},

{"product_name": "cotton blend work pants", "type": "pants", "price": 32.78},

{"product_name": "skinny suit trousers", "type": "pants", "price": 50.00},

{"product_name": "cotton blend knit joggers", "type": "pants", "price": 36.89},

{"product_name": "authentic stretch slim jeans", "type": "jeans", "price": 50.15},

{"product_name": "torino slim fit jeans", "type": "jeans", "price": 29.25},

{"product_name": "stretch skinny jeans", "type": "jeans", "price": 32.69},

{"product_name": "ripped coated skinny jeans", "type": "jeans", "price": 47.29},

{"product_name": "knee blowout slim jeans", "type": "jeans", "price": 56.29},

{"product_name": "puffer vest", "type": "jackets", "price": 102.50},

{"product_name": "hooded zip-up jacket", "type": "jackets", "price": 54.50},

{"product_name": "hooded bomber", "type": "jackets", "price": 69.50},

{"product_name": "flex bomber", "type": "jackets", "price": 72.29},

{"product_name": "velvet blazer", "type": "jackets", "price": 76.69},

{"product_name": "Suede jacket", "type": "jackets", "price": 67.15},

]

def filter_by_type(product_type, products):

"""Perform a filter on the online clothing store

catalog of known products based on product type

Args:

product_type(str): Product type

products(list[dict]): List of products to filter

Returns:

list[dict]: List of products matching filter criteria

"""

# Your code goes here

pass

def filter_by_max_price(price, products):

"""Perform a filter on the online clothing store

catalog of known products based on maximum price

Args:

price(float): The maximum price

products(list[dict]): List of products to filter

Returns:

list[dict]: List of products matching filter criteria

"""

# Your code goes here

pass

def filter_by_price_range(low, high, products):

"""Perform a filter on the online clothing store

catalog of known products based on price range

Args:

low(float): price range lower bound

high(float): price range upper bound

products(list[dict]): List of products to filter

Returns:

list[dict]: List of products matching filter criteria

"""

# Your code goes here

pass

def main():

"""Get input from the user about the filter criteria

and display matching products back to the user.

Products can be filtered using either a price range or

a maximum price.

If using maximum price, only one price is required.

If using a price range, two prices are required, i.e.

lower and upper bound of the price range.

"""

# Your code goes here

pass

if __name__ == "__main__":

products = [

{"product_name": "long sleeve polo", "type": "shirts", "price": 22.60},

{"product_name": "slim fit pocket joggers", "type": "pants", "price": 45.99},

{"product_name": "velvet blazer", "type": "jackets", "price": 76.69},

{"product_name": "dobby dress shirt", "type": "shirts", "price": 29.49},

{"product_name": "microcheck wool pants", "type": "pants", "price": 76.95},

]

# Q1.a filter_by_type

# shirts = filter_by_type("shirts", products)

# print(shirts)

# pants = filter_by_type("pants", products)

# print(pants)

# Q1.b filter_by_max_price

# filtered = filter_by_max_price(50.0, products)

# print(filtered)

# Q1.c filter_by_price_range

# product_range = filter_by_price_range(25.0, 50.0, products)

# print(product_range)

# Q1.d run the main function

# main()

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions