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
-
List the four approaches to implementation.
-
An engine absorbs 3500 J of heat energy each cycle and expels 1200 J. (a) How much work does it do in one cycle? (b) If it is a reversible heat engine and the hot reservoir is at 750 K, what is the...
-
Refer to Exercise 9. For the result that was statistically significant, the P-value was 0.01. What P-value would be needed to conclude at the = 0.05 level that the time spent studying differs...
-
A company attempted to build a Balanced Scorecard by fitting the companys objectives and financial and non financial performance measures into the four Balanced Scorecard perspectives. Explain why...
-
Indicate whether the following contracts are valid, void or voidable AND give the reason for the correct answer. Q.1.9 Richie buys two bottles of floor cleaner from Yellow Shoppe as he thinks that he...
-
You are a financial analyst in the financial planning and analysis department of WCC. You have been assigned the following: Complete a five-year forecast based on the above assumptions. Do you...
-
Consider the following equations that describe an open economy with government, where government transfers equal $0. C = 320+ 0.6YD 1936 Budget Balance = 0.2Y - 534 NX= 712 - 0.08Y Part a:...
-
what ways has the concept of negative interest rates challenged traditional views of monetary policy, and what are the potential risks associated with implementing such rates ?
-
Calculate the amount of the interest adjustment based on the figures provided in the following table. Assume it is not a leap year and use 7 decimals in your calculation. Round your final answers to...
-
How do you explain that fewer and fewer organizational management levels exist incorporations today. In other words, there is a flattening of the organizational pyramid. How does this phenomenon...
-
Explain the concept of moral hazard in the context of banking, and how it can lead to risky behavior by financial institutions.
-
What are our marketing objectives, and how do they align with our overall business goals? What messaging and tone resonate most effectively with our target audience?
-
Watch video links https://youtu.be/1S0RKRRyqhQ https://youtu.be/XrYujI3y4pg Take a moment to view both video and respond to the questions below. 1) The first video showed some basic emotions that we...
-
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....
-
Fernetti Advertising Agency was founded by John Fernetti in January of 2007. Presented below are both the adjusted and unadjusted trial balances as of December 31, 2008. Instructions (a) Journalize...
-
A review of the ledger of Remington Company at December 31, 2008, produces the following data pertaining to the preparation of annual adjusting entries. 1. Salaries Payable \($0.\) There are eight...
-
Givens Graphics Company was organized on January 1, 2008, by Sue Givens. At the end of the first 6 months of operations, the trial balance contained the following accounts. Analysis reveals the...
Study smarter with the SolutionInn App