Question
So Im having issues with calculating the average in my program Write a program to read the survey results into three lists and perform the
So Im having issues with calculating the average in my program
Write a program to read the survey results into three lists and perform the following analysis.
a) Print the record of each household included in the survey in a three-column format with headings.
b) Calculate and print the average household income.
c) List the identification number and income of each household that exceeds the average.
d) Determine and print the identification number and income of households that have income below the 2018 United States Contiguous States poverty level.
e) Determine and print the percentage of households that have income below the 2018 United States Contiguous States poverty level.
Compute the poverty level income using the formula below. povertyLevel = 16460.00 + 4320.00 * (m 2)
This is the input file
1042 12180.06 3 1062 13240.45 2 1327 19800.56 2 1483 22458.23 7 1900 17000.09 3 2112 18125 4 2345 15623 2 3210 3200 1 3600 39500 5 3601 11970 2 4724 8900 3 6217 45000.70 2 9280 6200 1 1000 31000 3 1200 36000 2 5601 51970 9 5724 66900 3 5217 10002.68 2 5280 70000 1 5000 100000 6 5200 25000.4 3 5230 120000 6 6641 85000 7 7000 45500 4 7100 56500 3 8110 110005.9 8 9101 67590.40 6
This is what I have so far but the average isnt right not sure what I'm doing wrong
def main(): inFile = open('program10.txt', 'r') outFile = open('program10-out.txt', 'w') outFile.write(str("%12s %12s %16s " % ("Account #", "Income", "Members"))) lineRead = inFile.readline() # Read first record while lineRead != '': # While there are more records words = lineRead.split() # Split the records into substrings acctNum = int(words[0]) # Convert first substring to integer annualIncome = float(words[1]) # Convert second substring to float members = int(words[2]) # Convert third substring to integer value = 12.5 print("%10d %15.2f %10d" % (acctNum, annualIncome, members)) outFile.write(str("%10d %16.2f %12d " % (acctNum, annualIncome, members))) lineRead = inFile.readline() # Read next record #call get_average function get_average(words[1]) # Close the file. inFile.close() # Close file
#Create a function to get the average household income def get_average(income_list): total = 0 for amount in range(len(income_list)): total += amount average = total/27 print (average)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started