Question: with Python: def main(): with open('sorted_income.txt', 'r') as infiles: ??? is that how you open the file Files to download: sorted_income.txt, test_sorted_nums.txt For this problem,

with Python:

def main(): with open('sorted_income.txt', 'r') as infiles: ??? is that how you open the file

Files to download: sorted_income.txt, test_sorted_nums.txt

For this problem, we gathered sample data from the Census Bureau, and youll use it to calculate some stats relating to household income in the US. The file, sorted_income.txt, is sorted in ascending order.

Use a while loop and Pythons readline() function to read one number at a time, and compute:

  • The number of incomes in the file

  • The average income (round when you print)

  • The median income

    • If the number of values is odd, the median is the value in the middle _ _ _ _ _

    • If the number of values is even, the median is the average of the middle two _ _ _ _ _ _

Our goal is to get these stats for the real data, sorted_income.txt. For full credit under documentation, though, first take a look at test_sorted_nums.txt, which is small and easy to compute what we need on paper. Figure out and comment with the expected stats on the test file. Do this before you start coding -- that way you know if your program works when you throw the bigger file at it.

# Expected from test_sorted_nums.txt

# Count: __

# Avg: __

# Median: ___

Make sure you dont assume anything about the number of values in the file, because your code should work for both even- and odd-sized files. You may need to open and read the file twice --- once to get the count and average, and once to get the median. Report all the stats to the user.

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!