Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language & Program: Python 3 on PyCharm 2018.1 Level: 100 ----- ----- Starter co

ID: 3904918 • Letter: L

Question

Language & Program: Python 3 on PyCharm 2018.1

Level: 100

-----

-----

Starter code:

Question 1 (5 points): Purpose: To practice slicing 2D arrays. Degree of Difficulty: Easy. Unilever Canada conducted a consumer's survey to identify which of its brands is losing popularity among consumers. Assume that there is one question per brand in the survey to find out consumer's inclination and level of satisfaction for each brand. They would like to know if more than 75% of the consumer gave negative comment to the brand i.e. greater than 75% of the consumers do not like to use the products of that brand. If increasing number of consumers are dissatisfied by a brand, it might indicate that marketing strategies must be reviewed. The file a6q1-starter.py contains two example survey responses from consumers as a list of lists where 1 indicates satisfaction and O indicates dissatisfaction for a brand. The first example, has the results of a survey of 5 customers regarding 4 brands; the second example is a survey completed by 20 customers regarding 10 brands. For each customer's response, assume that the question about first brand in the survey is at index 0, the second is at index 1. etc (that is, each sublist has the questions in the same order). It is recommended to test your program with smaller examples first then move on the bigger one. Create a program that will determine the percentage of consumers who are not satisfied by a brand in the survey, and will display the brand number for all brands where the fraction of consumers who are not satisfied by the brand is greater than 75%. Your program should work no matter how many consumers are there, or how many brands are there in the survey. To complete this question, you will need to: (a) Create a 2D array from the list of lists for a survey. (b) Calculate the percentage of consumers who are not satisfied by a brand in survey. (c) Print to the console the brand number for all brands where the fraction of consumers who are not satisfied by the brand is greater than 75%. Sample Run Here is an example execution of the required program. Greater than 75% of the consumer are not satisfied by Brand 1: Marketing strategies must be reviewed Greater than 75% of the consumer are not satisfied by Brand 2: Marketing strategies must be reviewed Greater than 75% of the consumer are not satisfied by Brand 3: Marketing strategies must be reviewed What to Hand In (a) A document entitled a6q1.py containing your finished program, as described above. Evaluation • 1 mark for creating a 2D array • 3 marks for calculating the percentages for each brand • 1 mark for correct console output NOTE: Use array to get marks for this question.

Explanation / Answer

def analyze(l):
    n = float(len(l))
    for i in range(len(l[0])):
        sum = 0.0
        for j in range(len(l)):
           
            if l[j][i] == 0:
               sum = sum + 1
      
        if sum/n > 0.75:
           print("Greater than 75% of the consumer are not satisfied by Brand",i+1, ":Marketing strategies must be breviewed")
   

survey1 = [ [0, 1, 0, 1],
            [0, 1, 0, 0],
            [1, 0, 0, 1],
            [0, 1, 0, 1],
            [1, 1, 0, 1]]

analyze(survey1)