Question
Version:0.9 StartHTML:0000000105 EndHTML:0000008229 StartFragment:0000000141 EndFragment:0000008189 In Python, a tuple is a collection similar to a list in that it is an ordered collection of items.
Version:0.9 StartHTML:0000000105 EndHTML:0000008229 StartFragment:0000000141 EndFragment:0000008189
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 grocery shopping() that takes a list of tuples called items_purchased that represent
CSE 101 Spring 2020 Homework #2 4items purchased at a grocery store. Each tuple contains three items, in this order:
the name of the item to purchase
the unit cost of the item in dollars
the number of units desired
The example tuple (Juice, 3, 5) indicates that we bought 3 units of Juice at $5 apiece, for a total of
$15.
The purpose of the function is to determine and return the name of the item that cost the most to buy.
You may assume that each named item occurs once in the list. For example, we would not fifind two tuples that
both have Juice as the item to purchase.
Examples:
Function Argument Return Value
[(Bread, 3, 3), (Eggs, 2, 3)] Bread
[(Milk, 5, 2), (Butter, 4, 1), (Juice, 1, 5),
(Eggs, 4, 3)]
Eggs
[(Milk, 2, 2), (Butter, 4, 1), (Juice, 3, 5),
(Eggs, 4, 3)]
Juice
[(Peas, 5, 2), (Meat, 3, 13), (Beer, 4, 12),
(Ice cream, 3, 5), (Eggs, 3, 3)]
Beer
[(Peas, 5, 2)] Peas
Note: The quotation marks displayed in the example return values are there to emphasize that the return values
are strings. Do not add quotation marks to the return values.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started