Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part II: Party Cost Calculator (20 points) Write a function party() that takes two arguments, in the following order: prices: A list of integers that

Part II: Party Cost Calculator (20 points)

Write a function party() that takes two arguments, in the following order:

prices: A list of integers that serves as a price book. This list always has four positive integers, with each

element representing the price of a particular item, and always in this order: The first element of the list (prices[0]) represents the cost of one pizza. The second element of the list (prices[1]) represents the cost of one cup. The third element of the list (prices[2]) represents the cost of one plate. The fourth element of the list (prices[3]) represents the cost of one soda.

shopping list: A list of strings that represents a shopping list. Each item is always one of pizza, cup, plate or soda. When an item appears multiple times, it means that multiple units of the item are bought. You may assume that the list will not contains any strings other than these four.

The function calculates and returns the total cost of the shopping list. However, there are a few discounts that might apply:

If five or more sodas are bought, apply an 8% discount to the total cost of all sodas. This discount can be used in addition to the entire shopping list discount, described next.

Only one of the following discounts to the entire cost might apply: a. If exactly two pizzas are bought, apply a 10% discount to the total cost of the entire shopping list. This

discount applies to the total cost after discount #1 is considered. b. If three or more pizzas are bought, apply a 20% discount to the total cost of the entire shopping list.

This discount applies to the total cost after discount #1 is considered. Again, only one of discounts 2(a) or 2(b) can be applied, not both.

An Example in Detail:

Functioncall:party([15, 1, 3, 2], [soda, soda, pizza, cup, cup, soda, pizza, plate, soda, soda, soda])

Sort it out a little bit, we have:

pizza 2, at $15 each. We have a 10% discount on the entire cost. cup 2, at $1 each plate 1, at $3 each soda 6, at $2 each. We have an 8% discount on the soda.

Calculate the total price before the 10% total discount is applied: (15 2) + (2 1) + (1 3) + (6 2) 0.92 = 46.04

Now we can apply the 10% total discount, and get our final return result:

46.04 0.9 = 41.436

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

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

=+. What does the competition offer that you don't?

Answered: 1 week ago