Question

Note: This is the only question for this star and only the age range will change. Save and test your code in repl.it so you can paste it for credit in case you don't get it right on the first try....

Note: This is the only question for this star and only the age range will change. Save and test your code in repl.it so you can paste it for credit in case you don't get it right on the first try. You are analyzing the results of a survey about the Internet and you want to know how often a specific age range of people use the Internet. You will be given a file containing a subset of the source data in the format "eminuse,intmob,intfreq,age" where all values are well-formed integers. This header will be the first line of the file and the column values are: eminuse Do you use the Internet? 1: yes 2: no intmob Do you use the Internet on mobile?

1: yes 2: no intfreq How often do you use the Internet? 1: Almost constantly 2: Several times a day 3: Once a day 4: Several times a week 5: Once a week or less Empty String: Responder answered 2 to eminuse and intmob age Responders age in years Note: The file has been filtered. If you download the original file you will have to add additional logic to handle responses of 8: Don't know, 9: Refused to answer, etc.

###The question is here in python. I can't seem to solve it

Write a function named "internet_histogram" that takes no parameters and does not return a value. There will be a file named "survey.csv" in the testing environment containing survey results as described above (the file has a header line which much be addressed by your code). Write a new file named "histogram.csv" containing 2 columns representing "internet_use,frequency" and no header line that will contain a histogram of the results of responders ages 34 to 53 including the endpoint ages. Your file will have exactly 6 lines with internet_use values of 1-5 corresponding to the intfreq results and 6 for responders who answered 2 to eminuse. Read the survey results file and track how many responders in this age range answered with each of these 6 options and write these counts to your "histogram.csv" file in order of internet_use starting with 1. Example histogram.csv: 1,5 2,7 3,0 4,1 5,2 6,4

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def internet_histogram():
count_6 = 0
count_5 = 0
count_4 = 0
count_3 = 0
count_2 = 0
count_1 = 0
with open("survey.csv",'r') as f:
    reader = csv.reader(f)
    with open("histogram.csv", 'w') as g:
        writer = csv.writer(g)
        next(reader)
        for line in reader:
            if int(line[3]) >= 31 and int(line[3]) <= 47:
                if int(line[0]) == 2:
                    count_6 +=1
                if line[2] != '':
                    if int(line[2]) == 1:
                        count_1 += 1
                    elif int(line[2]) == 2:
                        count_2 += 1
                    elif int(line[2]) == 3:
                        count_3 += 1
                    elif int(line[2]) == 4:
                        count_4 += 1
                    elif int(line[2]) == 5:
                        count_5 += 1
        arr = [[1, count_1], [2, count_2], [3, count_3], [4, count_4], [5, count_5], [6, count_6]]
        for i in arr:
            writer.writerow(i)
Add a comment
Know the answer?
Add Answer to:
Note: This is the only question for this star and only the age range will change. Save and test your code in repl.it so you can paste it for credit in case you don't get it right on the first try....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • Can you please provide the formula for the worksheet also. CASE PROBLEMS Level 1- Analyzing Sales...

    Can you please provide the formula for the worksheet also. CASE PROBLEMS Level 1- Analyzing Sales for Crèmes Ice Cream Judd Hemming is the eastern regional marketing manager for Crèmes Ice Cream. Eac quarter, he completes two separate analyses: an analysis comparing ice cream flavor sale volumes from all regional locations with the same quarter sales volumes from the previou year and an analysis comparing total sales in dollars, including mean, median, mode, and standard deviation, of sales by store....

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

  • Please read case article, "Attention Kmart Shoppers? Into and out of Bankruptcy" and help me come...

    Please read case article, "Attention Kmart Shoppers? Into and out of Bankruptcy" and help me come up with a solution for the case as well as action steps to implement the solution! Thank you!! ATTENTION KMART SHOPPERS? Former Kmart CEO, Charles C. Conaway, failed in his 19-month effort to revive the iconic firm, resulting in the largest retailing bankruptcy filing in history on January 22, 2002 (Davies, et al., 2002). On March 11, 2002, bankrupt Kmart named James B. Adamson...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT