Question: This Python program will analyze new and used car sales data that is stored in an input file. Each run of the program should analyze

This Python program will analyze new and used car sales data that is stored in an input file. Each run of the program should analyze one file of data. The name of the input file should be read from the user.

Here is a sample run of the program as seen in the console window. User input is shown in blue:

Welcome to the Car Sales Analyzer!

Enter the name of the data file: car_sales.txt

Used Cars

Under 10K: 12

10K - 20K: 5

Over 20K: 4

Average: 10515

New Cars

Under 30K: 6

30K to 45K: 11

Over 45K: 4

Average: 36751

Thanks for using the Car Sales Analyzer!

Your program should conform to the prompts and behavior displayed above. Include blank lines in the output as shown.

The analysis for used cars should count the number of cars sold in three categories: under 10,000 dollars, between 10,000 and 20,000 (inclusive), and over 20,000. Likewise, the count of new cars is separated into three categories: under 30,000 dollars, between 30,000 and 45,000 (inclusive), and over 45,000.

The average of each car type (new and used) is produced as well, truncating any fractional part.

Indent the results for each car type by three spaces as shown.

Each line of the data file will contain a code for the car type ('u' or 'U' for used and 'n' or 'N' for new) followed by one or more spaces followed by the sale price (an integer). You can assume that the data file requested will exist and will be in the proper format.

The analysis in the example above is from this data file. Here are the first few lines of that data:

u 4270 n 32450 U 8100 n 43880 N 47200 U 17570 u 12650 N 29640 U 22350

The program should include the following functions:

get_data - This function should accept two parameters: a string representing the input file name to process and the type of car ('u' or 'n') whose data is desired. The function should read the entire file and return a list of car prices (integers) for that type of car. The data for the other type are ignored. Use a with statement and for statement to process the input file as described in the textbook.

count_range - This function should accept three parameters: a list of sale prices, and minimum and maximum values of a range (2 integers). The function should count and return the number of values in the list that are in that range (inclusive).

main - This function represents the main program and accepts no parameters. It should read the file name to process from the user and, with the assistance of the other functions, produce all output. For this project, do not print output in any function other than main. The main function will end up calling the get_data function twice, and the count_range function six times. For range categories that have no stated maximum (such as "Over 20K") use 500,000 as the maximum.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!