Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code is in python, thank you! Part V: Candy Store Checkout (20 points) In Python, a tuple is a collection similar to a list in

image text in transcribed

code is in python, thank you!

Part V: Candy Store Checkout (20 points) In Python, a tuple is a collection similar to a list in that it is an ordered collection of items. An important difference, however, is that a tuple is immutable - once created, a tuple cannot be changed. Also, tuples are denoted using parentheses instead of square brackets. As with lists, elements of a tuple are accessed using indexing notation For example, given the tuple subjects = (, physics, , , chemistry, , , biology, ) , we could ac- cess the elements of the tuple using subjects[0], subjects[1] and subjects[2] Write a function checkout (), which takes a single argument, candies, which is a list of tuples,. Each tuple in the list indicates, in this order, (a) which kind of candy we are buying, (b) how many pieces of that candy we are buying (which we may assume is positive), and (c) the unit price of that kind of candy. For example, the tuple 'Gum', 15, 0.25) indicates we are buying 15 pieces of gum, which cost S0.25 apiece. The function always returns a floating-point value. A 10% discount is awarded on a particular item if the customer purchases 5 or more of that item. The discount applies to the entire lot of that item. You may assume that all pieces of a particular kind of candy are in a single lot. For example, the list of tuples would not have two or more separate tuples for Gum' Important: Do not perform any rounding in your calculations. Example #1: General case candies = [(,Warheads ,, 10, 1.0), ("crunch', 13, 0.8), (*Snickers,, 3, 1.22), 'Junior Mints', 9, 1.11), ('Mike and Ike, 2, 0.53) 1 Return value: 32.07 Example #2: Every item is discounted candies-[(' 5th Avenue', 7, 0.78), ' Crunch, 13, 0.75), Black Jack', 11, 1.49),'Krackel', 7, 0.92), 'Sour Patch Kids', 10, 0.89, 'AirHeads, 8, 0.69) 1 Return value: 47.21 Example #3: No items are discounted candies('Mars', 3, 1.11), ( Abba-Zaba, 3, 1.04), ('Pez, 1, 1.15), Junior Mints', 1, 1.4)1

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

Finance The Role Of Data Analytics In Manda Due Diligence

Authors: Ps Publishing

1st Edition

B0CR6SKTQG, 979-8873324675

Students also viewed these Databases questions