In: Computer Science
You have a theory that certain days of the week are most likely to be the highest sales You are to write a program that will test that theory.
Write a program that will have a list of 52 lists, each of those 52 lists must be of length 7 (that is they will each accommodate 7 items). Think of 52 weeks with 7 days in each week. Save a random value from 70 - 100 (inclusive of 70, exclusive of 100) in each of the days of each of the weeks.
Your code should analyze the list above and print a list of the number of times each day of the week had the highest sales. If more than one day had the highest sales of the week I do not care which of those days is recorded as the highest sales day.
Here is an example of the expected output: note that in the example below I generated and analyzed 5 weeks, you are to generate and analyze 52 weeks:
My code generated and output the following list of lists:
[[93, 98, 95, 75, 81, 88, 97], [91, 76, 81, 84, 72, 97, 83], [91, 81, 75, 72, 92, 95, 79], [98, 93, 88, 74, 93, 97, 82], [77, 86, 90, 87, 75, 84, 95]]
And output the following list after analysis of the above list:
[1, 1, 0, 0, 0, 2, 1]
The actual output from running my code was:
RESTART: /Users/janetbrownsederberg/Stonehill/Stonehill_Fall2020/HighestSales.py
[[93, 98, 95, 75, 81, 88, 97], [91, 76, 81, 84, 72, 97, 83], [91, 81, 75, 72, 92, 95, 79], [98, 93, 88, 74, 93, 97, 82], [77, 86, 90, 87, 75, 84, 95]]
[1, 1, 0, 0, 0, 2, 1]
>>>
Please have your output in the form above.
Please done in Python format
'''
Assumption : If sale value is more than 98 than than it
is counted as highest sales
Algorithm :
1. Creating a list of 52x7 using random module.
random.randint(70,10) is used to generate a random number
between 70 to 100 including 70 and 100
2. Transpose the list (by using help of numpy array) i.e.
Transpose it from 52x7 to 7x52.
3. Count the number of times each day of the week had
the highest sales.
4. Append this counting into the result list.
5. Print the result.
'''
#Anjeev Singh
#10-01-2020
import random
import numpy as np
sales=[] # empty list for sales
for n in range(52):
week=[] # empty list for week
for t in range(7):
week.append(random.randint(70,100)) # generate a random number and append to list.
sales.append(week) # appending week to sales list
arr = np.array(sales).T # creating an array with the help of list sales and stores it transpose
lisales = arr.tolist() # converting an array to list
highest_sales = [98,99,100] # Assume highest sales values
maxsale = [] # empty, to store frequency of max sale.
for i in range(7):
n = max(lisales[i])
print(lisales[i])
c = 0
if n >= 98:
for n in range(3):
c += lisales[i].count(highest_sales[n])
else:
c = 0
maxsale.append(c)
print("--------------")
print(sales)
print("--------------------")
print("after analysing ")
print(maxsale)
Note : above solution is given as per your explanation given in question paper. you have not clarify any conditions for assuming maximum sales of a day.
All the best.