Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When individuals list tickets on ticket resale sites they offer them in bundles - - a prospective buyer has to buy all the seats offered.

When individuals list tickets on ticket resale sites they offer them in bundles--a prospective buyer has to buy all the seats offered. The sellers provide the row and seat number of the seats they want to sell as well as the price they're offering the bundle for. When prospective buyers look for seats, however, they want to see them displayed by section.
Write a function display_tickets that has one parameter, the name of a file. The file has three pieces of information in each line: the section of the seats, the price of the bundle of seats for sale, and the seat numbers. Someone can sell anywhere from 1 to 8 seats, so after the row and the price there could be between 1 and 8 numbers. You can find an example of a file in seats.csv.
The name of the file is passed to the function as a variable name, like filename. Do NOT try to make the argument an actual file, like seats.csv. When the user calls the function, they will sub in a string that's the actual file name. Also remember that this file has to be in the same folder as the file that holds your code.
Your function should return a dictionary where the key is the row number (as a string) and its associated value is a list of 2-tuples, where each 2-tuple corresponds to a bundle of seats an individual is selling. The first element of the tuple is the price per seat in that bundle (not the price of the whole bundle), and the second is a list of seats in the bundle. Each seat should be represented as a string and not converted to a number format.
HINT: When you know the number of elements that you'll read in from each line of a file, it's common to use something called unpacking, or multiple assignment to do this with syntax like: a, b, c = line.split(). In this problem, though, each line may have a different number of elements, so the previous approach won't work. Instead you can assign the value of the result of your .split() command to a single variable. This will be a list that you can manipulate using your favorite list techniques.
If you use seats.csv as an example file, you'll call the function using display_tickets("seats.csv"), wrapped inside a print(), and your output should look like:
{
'141': [(350.0,['23','24','25','26']),(400.0,['38','39','40','41','42'])],
'511': [(766.6666666666666,['11','12','13']),(450.0,['25','26'])],
'900': [(200.0,['88','99'])],
'448': [(450.0,['01','02','03','04'])]
}

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

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

multiple choice...

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago