Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function party() that takes two arguments, in the following order: 1. prices: A list of integers that serves as a price book. This

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

1. 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.

2. 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:

1. 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.

2. 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:

Function call: 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

image text in transcribed

Examples: Function Call party ([113, 1, 1, 1], 'plate', 'soda,'soda plate', 'plate', 'pizza' ]]) party ([[10, 1, 2, 1],'soda', 'pizza', 'pizza, soda'plate' plate' ' cup' sodaCup' cup'plate' 'soda', 'cup'1 party ([[20, 2, 2, 3],'soda', soda', 'soda' plate', cup', 'pizza', soda, 'soda, soda, plate', soda', 'pizza', plate']]) party ([[13, 2, 4, 2],'cup', plate', 'plate, 'soda', cup, soda', 'plate', 'soda, 'plate', 'soda, 'plate', 'cup', 'pizza', 'plate', 'cup', 'soda cup,cup']]) party ([[11, 2, 3, 2], 'plate', 'plate, plate' cup', soda,'pizza', 'plate', 'plate', soda pizza', 'pizza']]) party ([[12, 2, 2, 3],'soda', cup', cup', soda'19 'soda', cup', cup', cup' ]]) party ([[18, 1, 4, 2],'soda', cup', plate' 'soda, cup, 'soda', 'soda','soda, 'plate' 'cup',soda'pizza'plate'cup'soda" 'soda','cup''platesoda'pizza11) party ([[16, 2, 4, 1],'soda', soda', 'cup', 'cup'58.400000000000006 cup', plate', 'pizza','pizza', 'plate', 'pizza', plate', cup', 'cup', 'soda'1 party ([[19, 1, 1, 1],'soda', 'pizza', 'cup' plate', soda', 'cup', 'plate', cup,'pizza', 'soda, 'soda', soda', 'pizza,up]]) party ([[19, 2, 3, 3],'soda', 'plate','cup','cup'74.77 'soda', cup, 'plate','soda', 'soda, soda', 'soda', 'pizza, 'plate', soda', 'pizza', 'soda plate', 'plate', 'cup']) Return Value 18 30.6 60.587999999999994 58.2 43.2 66.20400000000001 54.08

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

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

Students also viewed these Databases questions

Question

Describe the three causes of social loafing.

Answered: 1 week ago

Question

2. How should this be dealt with by the organisation?

Answered: 1 week ago

Question

explain what is meant by the term fair dismissal

Answered: 1 week ago