Answered step by step
Verified Expert Solution
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 bundlesa 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 displaytickets 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 to seats, so after the row and the price there could be between and 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 tuples, where each 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 displayticketsseatscsv wrapped inside a print and your output should look like:
:
:
:
:
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