Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define a function named add_to_orders(item_index, stock_list, orders) which takes an index, a list of products and a list of orders as parameters. The function should
Define a function named add_to_orders(item_index, stock_list, orders) which takes an index, a list of products and a list of orders as parameters. The function should do the following:
- Append a tuple consisting of the description and the price of the product at the specified index of the stock list onto the list of orders.
- Subtract 1 from the product's quantity value in the stock list.
- If the quantity is now 0, remove the product from the stock list.
Test | Input | Result |
---|---|---|
items = ['11,Coca Cola Soft Drink 500ml,4,2', '12,L & P Soft Drink Lemon & Paeroa 500ml,4,1', '13,V Blue Drink can 500mL,3.5,8', '14,V Vitalise Energy Drink 500ml,3.5,5'] orders = [] add_to_orders(0, items, orders) add_to_orders(1, items, orders) print(orders) print(items[0]) print(items[1]) | 5 | [('Coca Cola Soft Drink 500ml', '4'), ('L & P Soft Drink Lemon & Paeroa 500ml', '4')] 11,Coca Cola Soft Drink 500ml,4,1 13,V Blue Drink can 500mL,3.5,8 |
items = ['11,Coca Cola Soft Drink 500ml,4,1', '12,L & P Soft Drink Lemon & Paeroa 500ml,4,2', '13,V Blue Drink can 500mL,3.5,8', '14,V Vitalise Energy Drink 500ml,3.5,2', '15,Pump Water NZ Spring 750ml,2.5,3', '16,Twix Chocolate Bar 50g,2.5,12', '17,Nestle Kit Kat Chocolate Bar 4 Finger, 2.4,15', '18,Snickers Chocolate Bar 50g,2,11', '19,Cadbury Chocolate Bar Crunchie 50g, 2,13', '20,Cadbury Picnic Chocolate Bar 46g,2,15'] orders = [] add_to_orders(2, items, orders) add_to_orders(2, items, orders) add_to_orders(0, items, orders) add_to_orders(0, items, orders) print(orders) print(items[0]) print(items[1]) print(items[2]) | 10 | [('V Blue Drink can 500mL', '3.5'), ('V Blue Drink can 500mL', '3.5'), ('Coca Cola Soft Drink 500ml', '4'), ('L & P Soft Drink Lemon & Paeroa 500ml', '4')] 12,L & P Soft Drink Lemon & Paeroa 500ml,4,1 13,V Blue Drink can 500mL,3.5,6 14,V Vitalise Energy Drink 500ml,3.5,2 |
use python please.
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