1> 10 11 12 13 14 15 16 def finalPrice (prices): 17 T # Write your...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1> 10 11 12 13 14 15 16 def finalPrice (prices): 17 T # Write your code here 18 if __name__ == '__main__': 19 20 21 2722222222 23 24 25 26 28 29 #!/bin/python3... ✓ # # Complete the 'finalPrice' function below. # # The function accepts INTEGER_ARRAY prices as paramet # prices_count int(input().strip()) prices = [] for in range (prices_count): = prices_item = int(input().strip()) prices.append (prices_item) finalPrice (prices) 1. Final Discounted Price A shopkeeper has a sale to complete and has arranged the items being sold in an array. Starting from the left, the shopkeeper rings up each item at its full price less the price of the first lower or equal priced item to its right. If there is no item to the right that costs less than or equal to the current item's price, the current item is sold at full price. For example, assume there are items priced [2, 3, 1, 2, 4, 2]. The items 0 and 1 are each discounted by 1 unit, the first equal or lower price to the right. • Item 2, priced 1 unit sells at full price because there are no equal or lower priced items to the right. • The next item, item 3 at 2 units, is discounted 2 units to 0. • Item 4 at 4 units is discounted 2 units as well, so its final price is 2. • The final item 5 at 2 units must be purchased at full price because there are no lower prices to the right. The total cost is 1 + 2 + 1 + 0 + 2 + 2 = 8 units. The full price items are at indices [2, 5] using 0 based indexing. Function Description Complete the function finalPrice in the editor below. The function must print the total cost of all items on the first line. On the second line, print a space-separated list of integers representing the indices of the items purchased at full price, in ascending index order. finalPrice has the following parameter(s): prices[prices[0]....prices[n-1]]: an array of item prices Constraints • 1 ≤ n ≤ 105 • 1 ≤ prices[i] ≤ 106, where 0 ≤ i ≤ n ▾ Sample Case 0 Sample Input 0 STDIN 6 над шны 5 3 4 6 2 Function 14 15 → prices [] Size n = 6 prices = [5, 1, 3, 4, 6, 2] Sample Output 0 Explanation 0 The prices of the items are given by the array: index 0 1 2 3 4 5 prices = [5, 1, 3, 4, 6, 2] We can find the discount on each item: prices[0] = 5, first lower or equal price to the right = prices[1] = 1, discounted price = 5-1 = 4 • prices[1] = 1, lowest to the right = prices [5] = 2, no lower price to the right so no discount, price = 1 prices[2] = 3, first lower or equal = prices[5] = 2, discounted price = 3 - 2 = 1 • prices[3] = 4, first lower or equal = prices[5] = 2, discounted price = 4 - 2 = 2 • prices [4] = 6, first lower or equal = prices [5] = 2, discounted price = 6 - 2 = 4 • prices [5] = 2, no lower or equal to the right, so no discount, price = 2 The final discounted price is 4 + 1 + 1 + 2 + 4 + 2 = 14. There is no discount for item[1] or item[5]. Sample Case 1 Sample Input 1 STDIN 53 325 1 Sample Output 1 9 034 Function prices [] Size n = 5 prices = [1, 3, 3, 2, 5 ] Explanation 1 The prices of the items are given by the array: index 0 1 2 3 4 prices = [1, 3, 3, 2, 5] We can find the discount on each item: • prices [0] = 1, no lower or equal price to the right, no discount, price = 1 • prices[1] = 3, first lower or equal to the right = prices[2] = 3, discounted price = 3-3 = 0 • prices [2] = 3, first lower or equal to the right = prices[3] =2, discounted price = 3 - 2 = 1 • prices[3] = 2, no lower or equal price to the right, no discount, price = 2 • prices[4] = 5, no lower or equal price to the right, no discount, price = 5 The final discounted price is 1 + 0 + 1 + 2 + 5 =9. There is no discount for item [0], item[3] or item[4]. 10 11 12 13 14 15 16 17 18 #!/bin/python3... # # Complete the 'finalPrice' function below. # # The function accepts INTEGER_ARRAY prices as parameter. # def finalPrice (prices): # Write your code here 19 20 > if __name__ == '__main__': - 1> 10 11 12 13 14 15 16 def finalPrice (prices): 17 T # Write your code here 18 if __name__ == '__main__': 19 20 21 2722222222 23 24 25 26 28 29 #!/bin/python3... ✓ # # Complete the 'finalPrice' function below. # # The function accepts INTEGER_ARRAY prices as paramet # prices_count int(input().strip()) prices = [] for in range (prices_count): = prices_item = int(input().strip()) prices.append (prices_item) finalPrice (prices) 1. Final Discounted Price A shopkeeper has a sale to complete and has arranged the items being sold in an array. Starting from the left, the shopkeeper rings up each item at its full price less the price of the first lower or equal priced item to its right. If there is no item to the right that costs less than or equal to the current item's price, the current item is sold at full price. For example, assume there are items priced [2, 3, 1, 2, 4, 2]. The items 0 and 1 are each discounted by 1 unit, the first equal or lower price to the right. • Item 2, priced 1 unit sells at full price because there are no equal or lower priced items to the right. • The next item, item 3 at 2 units, is discounted 2 units to 0. • Item 4 at 4 units is discounted 2 units as well, so its final price is 2. • The final item 5 at 2 units must be purchased at full price because there are no lower prices to the right. The total cost is 1 + 2 + 1 + 0 + 2 + 2 = 8 units. The full price items are at indices [2, 5] using 0 based indexing. Function Description Complete the function finalPrice in the editor below. The function must print the total cost of all items on the first line. On the second line, print a space-separated list of integers representing the indices of the items purchased at full price, in ascending index order. finalPrice has the following parameter(s): prices[prices[0]....prices[n-1]]: an array of item prices Constraints • 1 ≤ n ≤ 105 • 1 ≤ prices[i] ≤ 106, where 0 ≤ i ≤ n ▾ Sample Case 0 Sample Input 0 STDIN 6 над шны 5 3 4 6 2 Function 14 15 → prices [] Size n = 6 prices = [5, 1, 3, 4, 6, 2] Sample Output 0 Explanation 0 The prices of the items are given by the array: index 0 1 2 3 4 5 prices = [5, 1, 3, 4, 6, 2] We can find the discount on each item: prices[0] = 5, first lower or equal price to the right = prices[1] = 1, discounted price = 5-1 = 4 • prices[1] = 1, lowest to the right = prices [5] = 2, no lower price to the right so no discount, price = 1 prices[2] = 3, first lower or equal = prices[5] = 2, discounted price = 3 - 2 = 1 • prices[3] = 4, first lower or equal = prices[5] = 2, discounted price = 4 - 2 = 2 • prices [4] = 6, first lower or equal = prices [5] = 2, discounted price = 6 - 2 = 4 • prices [5] = 2, no lower or equal to the right, so no discount, price = 2 The final discounted price is 4 + 1 + 1 + 2 + 4 + 2 = 14. There is no discount for item[1] or item[5]. Sample Case 1 Sample Input 1 STDIN 53 325 1 Sample Output 1 9 034 Function prices [] Size n = 5 prices = [1, 3, 3, 2, 5 ] Explanation 1 The prices of the items are given by the array: index 0 1 2 3 4 prices = [1, 3, 3, 2, 5] We can find the discount on each item: • prices [0] = 1, no lower or equal price to the right, no discount, price = 1 • prices[1] = 3, first lower or equal to the right = prices[2] = 3, discounted price = 3-3 = 0 • prices [2] = 3, first lower or equal to the right = prices[3] =2, discounted price = 3 - 2 = 1 • prices[3] = 2, no lower or equal price to the right, no discount, price = 2 • prices[4] = 5, no lower or equal price to the right, no discount, price = 5 The final discounted price is 1 + 0 + 1 + 2 + 5 =9. There is no discount for item [0], item[3] or item[4]. 10 11 12 13 14 15 16 17 18 #!/bin/python3... # # Complete the 'finalPrice' function below. # # The function accepts INTEGER_ARRAY prices as parameter. # def finalPrice (prices): # Write your code here 19 20 > if __name__ == '__main__': -
Expert Answer:
Answer rating: 100% (QA)
Python version 36 Python program to create and test function fin... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Partnership liquidation I only have a question on one part of my problem, so I am adding only the relevant data for my question. Noncash assets= 100,000 Tim, Capital(20%)=(15,000) 1. Before beginning...
-
Kopecky Industries Inc. is considering allocating a limited amount of capital investment funds among four proposals. The amount of proposed investment, estimated income from operations, and net cash...
-
Renaissance Capital Group is considering allocating a limited amount of capital investment funds among four proposals. The amount of proposed investment, estimated income from operations, and net...
-
Compute the determinant below. 14 8 8 8 51 1000 8 7 3 0 0 0 8 8 8 8 8 2
-
Rosa Salinas, CPA, is an assistant to the controller of Zebra Consulting Co. In her spare time, Rosa also prepares tax returns and performs general accounting services for clients. Frequently, Rosa...
-
Briefly describe the current requirement for companies in Mexico to account for the effect of inflation in their annual financial statements.
-
Which is of the following is accurate concerning the engagement partner and, as applicable, other engagement team members performing supervisory activities? (a) Inform engagement team members of...
-
Kate Petusky prepared Addison Controls' balance sheet and income statement for 2013. Before she could complete the statement of cash flows, she had to leave town to attend to a family emergency....
-
Consider a two period (t = 0, 1, 2) binomial model with u = 1.2, d = .9, continuously compounded interest rate r = 4.879%, and S = 100. The stock will pay no dividends. What are the values of...
-
Prepare a December 31 trial balance for Jindal Company using the following information and fill in the missing amount for Equipment (assume all data are correct). Cash Accounts payable Services...
-
As a technician in a large pharmaceutical research firm, you need to produce 150. mL of 1.00 mol L potassium phosphate buffer solution of pH = 7.09. The pKa of H2PO4 is 7.21. You have the following...
-
Robert was able to travel 244.0 miles in 4 hours and used 39 liters of gasoline. What was roberts speed in feet per second
-
What ways does organizational culture serve as a mechanism for social cohesion, and how does it impact employee engagement, retention, and overall job satisfaction ?
-
What can be interpreted on the capital structure of both companies (based on the debt and equity). What could be causing the difference in capital structure for both companies? 1) b) Do both...
-
Culture and diversity, MANAGING ORGANIZATIONAL BEHAVIOR SECOND EDITION) Identify issues in the workplace based on that week's readings (what is happening, background info - provide your mini case...
-
what ways can organizational culture influence decision-making processes, and how do you ensure those processes align with company values ?
-
The sprung parts of a vehicle weigh 9 . 7 9 kN , its center of gravity is 1 0 6 . 7 cm behind the front axle, and the wheelbase is 2 2 8 . 6 cm . The combined stiffness of the springs of the front...
-
Smthe Co. makes furniture. The following data are taken from its production plans for the year. Required: 1. Determine the hazardous waste disposal cost per unit for chairs and for tables if costs...
-
Abigail (Abby) Boxer is a single mother working as a civilian accountant for the U.S. Army. Her Social Security number is 676-73-3311 and she lives at 3456 Alamo Way, San Antonio, TX 78249. Helen,...
-
Karim Depak received a Form 1099-B showing the following stock transactions and basis during 2012: None of the stock is qualified small business stock. Calculate Karim's net capital gain or loss...
-
Steve Drake sells a rental house on January 1, 2012, and receives $130,000 cash and a note for $55,000 at 10 percent interest. The purchaser also assumes the mortgage on the property of $45,000....
-
On the Internet, find sites describing examples of the bill-and-hold technique.
-
Search the Internet for Thomas M. Coughlin, former Wal-Mart vice-chairman. What was he accused of in April 2005? What was his annual compensation in 2004?
-
Search the Internet for the improper transactions incurred by the A.I.G. What happened to the chairman Maurice R. Greenberg?
Study smarter with the SolutionInn App