Programming Project 3 : Automobile Sales
This 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 underlined:
Welcome to the Automobile Sales Analyzer!
Enter the name of the data file: sales.txt
New Automobiles
Total number sold: 24
Under 35K: 10
35K to 50K: 12
Over 50K: 2
Total sales: 926933
Average: 38622
Used Automobiles
Total number sold: 27
Under 12K: 18
12K 25K: 6
Over 25K: 3
Total sales: 328909
Average: 12181
Thanks for using the Automobile Sales Analyzer!
Your program should conform to the prompts and behavior displayed above. Include blank lines in the output as shown.
The analysis for new cars should count the number of cars sold in three categories: under 35,000 dollars, between 35,000 and 50,000 (inclusive), and over 50,000. Likewise, the count of used cars is separated into three categories: under 12,000 dollars, between 12,000 and 25,000 (inclusive), and over 25,000.
The total sales of each category (new and used) is printed, as is the average, truncating any fractional part.
Indent the results for each car type by three spaces as shown.
The Data File
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 Download this data file.
You can use that file to test your program, but your program should process any data file with a similar structure. The input file may be of any length and have any filename. You should test your program with at least one other data file that you make.
Your 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 open the file, 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 for statement to process the input file.
count_range This function should accept three parameters: a list of sale prices, and the 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 25K) use 500,000 as the maximum.
Other than the definitions of the functions described above, the only code in the module should be the following, at the end of the file: if __name__ == __main__:
main()
As before, that if statement keeps your program from being run when it is initially imported into the Web-CAT test environment. But your program will run as normal in Thonny. Note that there are two underscore characters before and after name and main.
Include an appropriate docstring comment below each function header describing the function.
Do NOT use techniques or code libraries that have not been covered in this course.
Include additional hashtag comments to your program as needed to explain specific processing.





Recent Comments