Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

And this is my code: from collections import namedtuple customer_name = '' current_date = '' whole = [] cart_items = [] ItemToPurchase = namedtuple('ItemToPurchase', 'item_name

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

And this is my code:

from collections import namedtuple customer_name = '' current_date = '' whole = [] cart_items = [] ItemToPurchase = namedtuple('ItemToPurchase', 'item_name item_price item_quantity item_description') ShoppingCart = namedtuple("ShoppingCart", "customer_name current_date cart_items")

def construct_cart(): customer_name = 'none' current_date = "January 1, 2016" cart_items = [] anything = ShoppingCart(customer_name,current_date,cart_items) def construct_item(): return ItemToPurchase(item_name = 'none', item_price = 0, item_quantity = 0, item_description = 'none') def print_item_description(ItemtoPurchase): print("{}: {}".format(ItemtoPurchase.item_name,ItemtoPurchase.item_description)) def print_item_cost(ItemtoPurchase): print(ItemtoPurchase.item_name + ' ' + ItemtoPurchase.item_quantity + ' @ $' + ItemtoPurchase.item_price + ' = ' + '$' + str(int(ItemtoPurchase.item_quantity) * int(ItemtoPurchase.item_price))) def add_item(ShoppingCart ,ItemToPurchase): print("ADD ITEM TO CART") item_na = input("Enter the item name: ") item_de = input("Enter the item description: ") item_pr = input("Enter the item price: ") item_qu = input("Enter the item quantity: ") name = ShoppingCart(item_na,item_de,item_pr,item_qu) whole.append(name) cart_items.append(ShoppingCart) cart_items.append(ItemToPurchase)

def modify_item(ShoppingCart,ItemToPurchase): change_of_name = input() def print_total(): print("OUTPUT SHOPPING CART") print()

def remove_item(ShoppingCart,string): num = 0 for i in cart_items: if string == i: cart_items.remove(i) else: num += 1 if num == len(cart_items): print("Item not found in cart. Nothing removed.") def print_menu(ShoppingCart): print("MENU a - Add item to cart r - Remove item from cart c - Change item quantity i - Output items' descriptions o - Output shopping cart q - Quit ") choice = input('Choose an option: ') choice_list = ['a','r','c','i','o','q'] while choice not in choice_list: choice = input('Choose an option: ') while choice != 'q': if choice == 'a': add_item(ShoppingCart ,ItemToPurchase) choice = input('Choose an option: ') elif choice == 'r': string = input("Enter name of item to remove:") remove_item(ShoppingCart,string) choice = input('Choose an option: ') elif choice == 'c': modify_item(ShoppingCart,ItemToPurchase) choice = input('Choose an option: ') elif choice == 'i': choice = input('Choose an option: ') elif choice == 'o': choice = input('Choose an option: ') if __name__ == "__main__": customer_Name = input("Enter customer's name: ") date_today = input("Enter today's date: ") print("Customer name: {}".format(customer_Name)) print("Today's date: {}".format(date_today)) print() print_menu(ShoppingCart)

7.11 LAB: Online shopping cart Part 2 This program extends the earlier "Online shopping cart program. (Consider first saving your earlier program) (1) Extend the Item ToPurchase namedtuple to contain a new attribute. (2 pts) item_description (string)- Set to "none" in the construct tuple0 function Implement the following function with an ItemToPurchase as a parameter. print_item_description0 - Prints item_name and item_description attribute for an ItemToPurchase namedtuple. Has an ItemToPurchase parameter. Ex. of print item_description output Bottled Water: Deer Park, 12 oz (2) Build a ShoppingCart namedtuple with the following data attributes and related functions. Note: Some can be function stubs (empty methods) initially, to be completed in later steps. Create a namedtuple named ShoppingCart which has the customer name. date, and cart items as attributes (2 pts) . customer_name (string) current.date (string) cartitems (list) Write a function named construct.cart0 for ShoppingCart that creates a named tuple with the following specifications: (1 pt) Initializes customer_name "none, current date "January 1,2016, cart items to an empty list Functions add_item Adds an item to cart-items list. Has parameters ShoppingCart and itemToPurchase. Does not return anything. remove item Removes item from cart items list. Has a ShoppingCart and a string (an item's name) as parameters. Does not return anything If item name cannot be found, output this message: Item not found in cart. Nothing removed modify_item Modifies an item's description, price, and/or quantity. Has parameters ShoppingCart, and ItemToPurchase. Does not return anything. If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify modify_item Modifies an item's description, price, and/or quantity. Has parameters ShoppingCart, and Item ToPurchase. Does not return anything If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify tem in cart. .get num_items_in_cart0 (2 pts) get_cost of cart0 (2 pts) print total0 If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified o Returns quantity of all items in cart. Has a ShoppingCart as a parameter. o Determines and returns the total cost of items in cart. Has a ShoppingCart as a parameter Outputs total of objects in cart. o Has a ShoppingCart as a parameter o If cart is empty, output this message: SHOPPING CART IS EMPTY print_descriptions0 Outputs each items description. o Has a ShoppingCart as a parameter x. of print total0 output: John Doe's Shopping Cart February 1, 2016 Number of Items: 8 Nike Romaleos 2 @ $189 = $378 Chocolate Chips 5 $3-$15 Powerbeats 2 Headphones 1 C $128$128 Total: $521 x. of print_descriptions0 output: John Doe's Shopping Cart February 1, 2016 Item Descriptions Nike Romaleos: Volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones (3) In main section of your code, prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart. (1 pt) Ex. Enter customer's name: John Doe Enter today's date: February 1, 2016 Customer name: John Doe Today' s date: February 1, 2016 (4) Implement the print menu function. print menu0 has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the function. If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call print_menu0 in the main0 function. Continue to execute the menu until the user enters q to Quit. (3 pts) Ex: MENU a Add item to cart r- Remove item from cart c - Change item quantity i Output items' descriptions o Output shopping cart -Quit Choose an option: (5) Implement Output shopping cart menu option. (3 pts) Ex: OUTPUT SHOPPING CART John Doe's Shopping Cart February 1, 2016 Number of Items: 8 OUTPUT SHOPPING CART John Doe's Shopping Cart -February 1, 2016 Number of Items:8 Nike Romaleos 2 $189 $378 Chocolate Chips 5$3$15 Powerbeats 2 Headphones 1 @ $128 = $128 Total: $521 6) Implement Output item's description menu option. (2 pts) Ex OUTPUT ITEMS DESCRIPTIONS John Doe's Shopping Cart February 1, 2016 Item Descriptions Nike Romaleos: volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones (7) Implement Add item to cart menu option. (3 pts) Ex: ADD ITEM TO CART Enter the item name: Nike Romaleos Enter the item description: Volt color, Weightlifting shoes Enter the item price: 189 Enter the item quantity: 2 (8) Implement remove item menu option.(4 pts) Ex: REMOVE ITEM FROM CART Enter name of item to remove: Chocolate Chips 9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object before using Modifyltem method. (5 pts) Ex: CHANGE ITEM QUANTITY Enter the item name: Nike Romaleos Enter the new quantity: 3 6: Compare output ^ John Doe Input February 1, 2016 Enter customer' s name: Enter today' s date: Your output correctly starts with Customer name: John Doe Today' s date: February 1, 2016 7: Compare output A 3/3 John Doe February 1, 2016 Input f Enter customer' s name: Enter today' s date: Customer name John Doe Today' s date: February 1, 2016 MENU a Add item to cart Your output r - Remove item from cart c - Change item quantity - Output items' descriptions oOutput shopping cart Quit Choose an option: Choose an option: Choose an option: 8: Compare output A 0/3 Output differs. See highlights below. Special character legend February 1, 2016 Input Enter customer's name: Enter today's date:e Customer name: John Doe Today' s date: February 1, 2016 MENU Your output ends a Add item to cart with r- Remove item from cart c - Change item quantity iOutput items' descriptions oOutput shopping cart -Quite Choose an option: Choose an option: OUTPUT SHOPPING CARTe John Doe's Shopping cart - F Number of Items: 0d February 1,2016 SHOPPING CART IS EMPTYd Total: S0 Expected output ends witlh MENU a Add item to cart r- Remove item from cart c - Change item quantity iOutput items' descriptions oOutput shopping cart 11: Compare output Output differs. See highlights below. Special character legend John Doe February 1, 2016 Nike Roma!eos Volt color, Weightlifting shoes 189 Chocolate Chips semi-sweet Input 3 Powerbeats 2 Headphones Bluetooth headphones 128 Chocolate Chips REMOVE ITEM FRON CART Enter name of item to remove: MENU aAdd item to cart rRemove item from cart c Change item quantity iOutput items' descriptions Output shopping cart q - Quit Choose an option: OUTPUT SHOPPING CART John Doe'a shopping Cartbruary 1, 2016 Expected output Number of Items: 3 ends with Nke Romaleos 2@ $189 = $378 Powerbeats 2 Headphones 1e $128$128 Total: $506 MENU a-Add item to cart Remove item from cart Change item quantity Output items' descriptions ooutput shopping carte Quite hoose an option: Outrput differs. Se highlighits bko Special character legend John Doe February 1, 2016 Nike Romaleos Volt color, Weightlifting shoes 189 Chocolate Chips Input Semi-sweet 3 Powerbeats 2 Headphones Blue 128 tooth headphones 9 Outrput differs. Se highlighits bko Special character legend John Doe February 1, 2016 Nike Romaleos Volt color, Weightlifting shoes 189 Chocolate Chips Input Semi-sweet 3 Powerbeats 2 Headphones Blue 128 tooth headphones 9 7.11 LAB: Online shopping cart Part 2 This program extends the earlier "Online shopping cart program. (Consider first saving your earlier program) (1) Extend the Item ToPurchase namedtuple to contain a new attribute. (2 pts) item_description (string)- Set to "none" in the construct tuple0 function Implement the following function with an ItemToPurchase as a parameter. print_item_description0 - Prints item_name and item_description attribute for an ItemToPurchase namedtuple. Has an ItemToPurchase parameter. Ex. of print item_description output Bottled Water: Deer Park, 12 oz (2) Build a ShoppingCart namedtuple with the following data attributes and related functions. Note: Some can be function stubs (empty methods) initially, to be completed in later steps. Create a namedtuple named ShoppingCart which has the customer name. date, and cart items as attributes (2 pts) . customer_name (string) current.date (string) cartitems (list) Write a function named construct.cart0 for ShoppingCart that creates a named tuple with the following specifications: (1 pt) Initializes customer_name "none, current date "January 1,2016, cart items to an empty list Functions add_item Adds an item to cart-items list. Has parameters ShoppingCart and itemToPurchase. Does not return anything. remove item Removes item from cart items list. Has a ShoppingCart and a string (an item's name) as parameters. Does not return anything If item name cannot be found, output this message: Item not found in cart. Nothing removed modify_item Modifies an item's description, price, and/or quantity. Has parameters ShoppingCart, and ItemToPurchase. Does not return anything. If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify modify_item Modifies an item's description, price, and/or quantity. Has parameters ShoppingCart, and Item ToPurchase. Does not return anything If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify tem in cart. .get num_items_in_cart0 (2 pts) get_cost of cart0 (2 pts) print total0 If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified o Returns quantity of all items in cart. Has a ShoppingCart as a parameter. o Determines and returns the total cost of items in cart. Has a ShoppingCart as a parameter Outputs total of objects in cart. o Has a ShoppingCart as a parameter o If cart is empty, output this message: SHOPPING CART IS EMPTY print_descriptions0 Outputs each items description. o Has a ShoppingCart as a parameter x. of print total0 output: John Doe's Shopping Cart February 1, 2016 Number of Items: 8 Nike Romaleos 2 @ $189 = $378 Chocolate Chips 5 $3-$15 Powerbeats 2 Headphones 1 C $128$128 Total: $521 x. of print_descriptions0 output: John Doe's Shopping Cart February 1, 2016 Item Descriptions Nike Romaleos: Volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones (3) In main section of your code, prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart. (1 pt) Ex. Enter customer's name: John Doe Enter today's date: February 1, 2016 Customer name: John Doe Today' s date: February 1, 2016 (4) Implement the print menu function. print menu0 has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the function. If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call print_menu0 in the main0 function. Continue to execute the menu until the user enters q to Quit. (3 pts) Ex: MENU a Add item to cart r- Remove item from cart c - Change item quantity i Output items' descriptions o Output shopping cart -Quit Choose an option: (5) Implement Output shopping cart menu option. (3 pts) Ex: OUTPUT SHOPPING CART John Doe's Shopping Cart February 1, 2016 Number of Items: 8 OUTPUT SHOPPING CART John Doe's Shopping Cart -February 1, 2016 Number of Items:8 Nike Romaleos 2 $189 $378 Chocolate Chips 5$3$15 Powerbeats 2 Headphones 1 @ $128 = $128 Total: $521 6) Implement Output item's description menu option. (2 pts) Ex OUTPUT ITEMS DESCRIPTIONS John Doe's Shopping Cart February 1, 2016 Item Descriptions Nike Romaleos: volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones (7) Implement Add item to cart menu option. (3 pts) Ex: ADD ITEM TO CART Enter the item name: Nike Romaleos Enter the item description: Volt color, Weightlifting shoes Enter the item price: 189 Enter the item quantity: 2 (8) Implement remove item menu option.(4 pts) Ex: REMOVE ITEM FROM CART Enter name of item to remove: Chocolate Chips 9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object before using Modifyltem method. (5 pts) Ex: CHANGE ITEM QUANTITY Enter the item name: Nike Romaleos Enter the new quantity: 3 6: Compare output ^ John Doe Input February 1, 2016 Enter customer' s name: Enter today' s date: Your output correctly starts with Customer name: John Doe Today' s date: February 1, 2016 7: Compare output A 3/3 John Doe February 1, 2016 Input f Enter customer' s name: Enter today' s date: Customer name John Doe Today' s date: February 1, 2016 MENU a Add item to cart Your output r - Remove item from cart c - Change item quantity - Output items' descriptions oOutput shopping cart Quit Choose an option: Choose an option: Choose an option: 8: Compare output A 0/3 Output differs. See highlights below. Special character legend February 1, 2016 Input Enter customer's name: Enter today's date:e Customer name: John Doe Today' s date: February 1, 2016 MENU Your output ends a Add item to cart with r- Remove item from cart c - Change item quantity iOutput items' descriptions oOutput shopping cart -Quite Choose an option: Choose an option: OUTPUT SHOPPING CARTe John Doe's Shopping cart - F Number of Items: 0d February 1,2016 SHOPPING CART IS EMPTYd Total: S0 Expected output ends witlh MENU a Add item to cart r- Remove item from cart c - Change item quantity iOutput items' descriptions oOutput shopping cart 11: Compare output Output differs. See highlights below. Special character legend John Doe February 1, 2016 Nike Roma!eos Volt color, Weightlifting shoes 189 Chocolate Chips semi-sweet Input 3 Powerbeats 2 Headphones Bluetooth headphones 128 Chocolate Chips REMOVE ITEM FRON CART Enter name of item to remove: MENU aAdd item to cart rRemove item from cart c Change item quantity iOutput items' descriptions Output shopping cart q - Quit Choose an option: OUTPUT SHOPPING CART John Doe'a shopping Cartbruary 1, 2016 Expected output Number of Items: 3 ends with Nke Romaleos 2@ $189 = $378 Powerbeats 2 Headphones 1e $128$128 Total: $506 MENU a-Add item to cart Remove item from cart Change item quantity Output items' descriptions ooutput shopping carte Quite hoose an option: Outrput differs. Se highlighits bko Special character legend John Doe February 1, 2016 Nike Romaleos Volt color, Weightlifting shoes 189 Chocolate Chips Input Semi-sweet 3 Powerbeats 2 Headphones Blue 128 tooth headphones 9 Outrput differs. Se highlighits bko Special character legend John Doe February 1, 2016 Nike Romaleos Volt color, Weightlifting shoes 189 Chocolate Chips Input Semi-sweet 3 Powerbeats 2 Headphones Blue 128 tooth headphones 9

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

Step: 3

blur-text-image

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

What is the nth derivative of ln(x)?

Answered: 1 week ago

Question

1. Why do people tell lies on their CVs?

Answered: 1 week ago

Question

2. What is the difference between an embellishment and a lie?

Answered: 1 week ago