Program Behavior This program will analyze real estate sales data stored in an input file. Each run...

80.2K

Verified Solution

Question

Programming

Program Behavior

This program will analyze real estate sales data stored in aninput file. Each run of the program should analyze one file ofdata. The name of the input file should be read from the user.

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

Let's analyze those sales!

Enter the name of the file to process? sales.txt

Number of sales: 6

Total: 2176970

Average: 362828

Largest sale: Joseph Miller 610300

Smallest sale: Franklin Smith 199200

Now go sell some more houses!

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

Each line of the data file analyzed will contain the buyer'slast name, the buyer's first name, and the sale price, inthat order and separated by spaces. You can assume thatthe data file requested will exist and be in the proper format.

The data file analyzed in that example contains this data:

Cochran Daniel 274000
Smith Franklin 199200
Espinoza Miguel 252000
Miller Joseph 610300
Green Cynthia 482370
Nguyen Eric 359100

You can download that sample data file herehttps://drive.google.com/file/d/1bkW8HAvPtU5lmFAbLAJQfOLS5bFEBwf6/view?usp=sharingto test your program, but your program should process any data filewith a similar structure. The input file may be of any length andhave any filename. You should test your program with at least oneother data file that you make.

Note that the average is printed as an integer, truncating anyfractional part.

Your program should include the following functions:

read_data - This function should accept astring parameter representing the input file name to process andreturn a list containing the data from the file. Each element inthe list should itself be a list representing one sale. Eachelement should contain the first name, last name, and purchaseprice in that order (note that the first and lastnames are switched compared to the input file). For the examplegiven above, the list returned by the read_data function wouldbe:

[['Daniel', 'Cochran', 274000], ['Franklin', 'Smith', 199200],['Miguel', 'Espinoza', 252000], ['Joseph', 'Miller', 610300],['Cynthia', 'Green', 482370], ['Eric', 'Nguyen', 359100]]

Use a with statement and forstatement to process the input file as described in thetextbook.

compute_sum - This function should accept thelist of sales (produced by the read_data function) as a parameter,and return a sum of all sales represented in the list.

compute_avg - This function should accept thelist of sales as a parameter and return the average of all salesrepresented in the list. Call the compute_sum function to help withthis process.

get_largest_sale - This function should acceptthe list of sales as a parameter and return the entry in the listwith the largest sale price. For the example above, the returnvalue would be ['Joseph', 'Miller', 610300].

get_smallest_sale - Like get_largest_sale, butreturns the entry with the smallest sale price. For the exampleabove, the return value would be ['Franklin', 'Smith', 199200].

Do NOT attempt to use the built-in functions sum, min, or max inyour program. Given the structure of the data, they are not helpfulin this situation.

main - This function represents the mainprogram, which reads the file name to process from the user and,with the assistance of the other functions, produces all output.For this project, do not print output in any function other thanmain.

Other than the definitions of the functions described above, theonly code in the module should be the following, at the end of thefile:

if __name__ == '__main__':
main()

That if statement keeps your program from beingrun when it is initially imported into the Web-CAT testenvironment. But your program will run as normal in Thonny. Notethat there are two underscore characters before and aftername and main.

Include an appropriate docstring comment below each functionheader describing the function.

Do NOT use techniques or code libraries that have not beencovered in this course.

Include additional hashtag comments to your program as needed toexplain specific processing.

A Word about List Access

A list that contains lists as elements operates the same waythat any other lists do. Just remember that each element is itselfa list. Here's a list containing three elements. Each element is alist containing integers as elements:

my_list = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]

So my_list[0] is the list [1, 2, 3, 4] and my_list[2] is [9, 10,11, 12].

Since my_list[2] is a list, you could use an index to get to aparticular value. For instance, my_list[2][1] is the integer value10 (the second value in the third list in my_list).

In this project, the sales list is a list of lists. When needed,you can access a particular value (first name, last name, or salesprice) from a particular element in the sales list.

Answer & Explanation Solved by verified expert
3.9 Ratings (675 Votes)
ef readdatafilenamedataFromFilewith openfilenamer as filedatafilereadlinesdataistripfor i in    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students