Write a function named area_codes that prints information about the most commonly occurring area code in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function named area_codes that prints information about the most commonly occurring area code in a file of telephone numbers. Your function accepts a string parameter representing a filename of input. The input file contains a collection of telephone numbers, one per line, in the following format. Each phone number begins with a three-digit area code. You may assume that every line of the file is in exactly the format shown, without any other characters or formatting or spacing, and that every phone number in the file is unique. 650-723-2273 206-685-2181 800-356-9377 800-347-3288 650-725-7411 520-297-6312 206-543-1695 800-266-2278 206-543-2969 Your function should open and read the contents of this input file and figure out which area code occurs most frequently in the data. If multiple area codes are tied for being the most frequent, print the numerically smallest of the ones that tied. For example, in the data at right, the most common area codes are 800 and 206, each of which has 3 phone numbers with that area code, so your function should consider 206 to be the most commonly occurring area code. After determining which is the most common area code, your function should prout all of the phone numbers from that area code, in sorted numerical order, one per line. For example, if the input above at right comes from a file named phonenumbers.txt, then the call of area_codes ("phone numbers, txt") should print the following console output: 206-543-1695 206-543-2969 206-685-2181 If the file is missing or unreadable, your function should produce no output. If the file exists, you may assume that it contains at least one phone number, that every line of input in the file is in the exact valid format described above, and that every phone number in the file will be unique. Constraints: • You may open and read the file only once. Do not re-open it or rewind the stream. • You should choose an efficient solution. Choose data structures intelligently and use them properly. • You may create one collection (stack, queue, set, map, etc.) or nested/compound structure as auxiliary storage. A nested structure, such as a set of lists, counts as one collection. A temporary collection variable that is merely a replica or reference to some other collection (such as, v= mylist.remove()) is fine and does not count as a second structure. (You can have as many simple variables as you like, such as ints or strings.) Write a function named area_codes that prints information about the most commonly occurring area code in a file of telephone numbers. Your function accepts a string parameter representing a filename of input. The input file contains a collection of telephone numbers, one per line, in the following format. Each phone number begins with a three-digit area code. You may assume that every line of the file is in exactly the format shown, without any other characters or formatting or spacing, and that every phone number in the file is unique. 650-723-2273 206-685-2181 800-356-9377 800-347-3288 650-725-7411 520-297-6312 206-543-1695 800-266-2278 206-543-2969 Your function should open and read the contents of this input file and figure out which area code occurs most frequently in the data. If multiple area codes are tied for being the most frequent, print the numerically smallest of the ones that tied. For example, in the data at right, the most common area codes are 800 and 206, each of which has 3 phone numbers with that area code, so your function should consider 206 to be the most commonly occurring area code. After determining which is the most common area code, your function should prout all of the phone numbers from that area code, in sorted numerical order, one per line. For example, if the input above at right comes from a file named phonenumbers.txt, then the call of area_codes ("phone numbers, txt") should print the following console output: 206-543-1695 206-543-2969 206-685-2181 If the file is missing or unreadable, your function should produce no output. If the file exists, you may assume that it contains at least one phone number, that every line of input in the file is in the exact valid format described above, and that every phone number in the file will be unique. Constraints: • You may open and read the file only once. Do not re-open it or rewind the stream. • You should choose an efficient solution. Choose data structures intelligently and use them properly. • You may create one collection (stack, queue, set, map, etc.) or nested/compound structure as auxiliary storage. A nested structure, such as a set of lists, counts as one collection. A temporary collection variable that is merely a replica or reference to some other collection (such as, v= mylist.remove()) is fine and does not count as a second structure. (You can have as many simple variables as you like, such as ints or strings.)
Expert Answer:
Answer rating: 100% (QA)
def areacodesfilename try datamap of lists maxCount0 maxCountcode999 wi... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Answer these questions What is Nihilism? 2. Describe the evil crime that Leopold and Loeb committed in Chicago in the early 1950's 3. Describe Juds ( Mr. Leob) conversation with Ruth at the bar...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
(1) (a) Discretize the 2D Poisson equation Vu(x, y) = Uxx + Uyy = = p(x, y) with second-order accurate central differences with Ax = the given charge density. Ay=h. p(x, y) is (b) Express uij in...
-
Ridge Crest Company has beginning Retained Earnings of $39,000, ending Retained Earnings of $41,500, and a net income of $23,500. What was the amount of dividends declared during the year: $15,500...
-
Dollar Discount Store is a local discount store with the following information: October sales are projected to be $300,000. Sales are projected to increase by 10% in November and another 20% in...
-
Which of the following statement(s) is/are true with regard to positional information in Drosophila? A. Morphogens are a type of molecule that conveys positional information. B. Morphogenetic...
-
What do we mean by the term relevant evidence?
-
Jewel Pix currently uses a six-year-old molding machine to manufacture silver picture frames. The company paid $85,000 for the machine, which was state of the art at the time of purchase. Although...
-
K On June 30, 2020, the market interest rate is 5.1%. Enderby Enterprises issues $515,000 of 6.1%, 18-year bonds at 113.944. The bonds pay inte amortizes bonds by the effective-interest method....
-
In preparing for the upcoming holiday season, Mandrell Toy Company designed a new doll called Freddy. The fixed cost to produce the doll is $100,000. The variable cost, which includes material,...
-
Chemical and physical changes sometimes result in the production of a gas. Imagine such a scenario and describe two possible observations you might expect to make as evidence that a change produced a...
-
Consider the non-linear model: with and Yij (Bo+boi) e e-(+bui)tij - + Eij; Eij ~ N(0,02), boi doo do (3) ~ ~[(- ( de ))] di (1) Consider the above model for the outcome 'dose' and covariate 'group'....
-
A bond with face value $1,000 has a current yield of 6.5% and a coupon rate of 8.5%. a. If interest is paid annually, what is the bond's price?
-
You are bearish on Apple Stock and decide to short sell the stock. You sell 3000 shares at $20/share. You are required to post an initial margin of 50% and pay in maintenance margin if the margin...
-
Skysong Motor Company manufactures automobiles. During September 2022, the company purchased 4,000 head lamps at a cost of $10 per lamp. 30 of these lamps were used to replace the head lamps in autos...
-
Mr. A. borrowed $ 75,000 at an interest rate of 5% per annum, payable over 4 years.The debt is amortized for 4 payments with the same amount at each end year. a. Calculate the annual payment the same...
-
Suppose that the weight of a newborn fawn is Uniformly distributed between 1.6 and 3.2 kg. Suppose that a newborn fawn is randomly selected. Round answers to 4 decimal places when possible. Find the...
-
Sportique Boutique reported the following financial data for 2012 and 2011. Instructions(a) Calculate the current ratio for Sportique Boutique for 2012 and 2011.(b) Suppose that at the end of 2012,...
-
What does the following program segment output? d = 0; do { System.out.print(d + " "); d++; } while (d < 2); a. 0 b. 0 1 c. 0 1 2 d. Nothing
-
Carlys Catering provides meals for parties and special events. Write a program that displays Carlys motto, which is Carlys makes the food that makes it a party. Save the file as CarlysMotto.java....
-
The init() method is used for ____________. A. Pausing a javafx application B. Extending the application class C. Constructing a specified instance of the application class D. Performing...
-
Four identical rigid bars-each of length \(a\) - are connected to a spring of stiffness \(k\) to form a structure for carrying a vertical load \(P\), as shown in Figs. 1.72 (a) and (b). Find the...
-
A cantilever beam of length \(L\) and Young's modulus \(E\) is subjected to a bending force at its free end. Compare the spring constants of beams with cross sections in the form of a solid circle...
-
A bar of length \(L\) and Young's modulus \(E\) is subjected to an axial force. Compare the spring constants of bars with cross sections in the form of a solid circle (of diameter \(d\) ), square (of...
Study smarter with the SolutionInn App