In: Computer Science
SAT Score Analysis
You have been asked to analyze SAT scores (which may be 400 - 1600).
You will be analyzing a population (a list) which consists of a number of
samples (lists) of student scores.
Here is the code to generate the population/samples:
import random
population=[]
for i in range(5):
sample = []
n = random.randint(5,10)
for num in range(n):
sample.append(random.randrange(400,1600))
population.append(sample)
The analysis should be conducted as follows:
##calculate the total number of scores
##calculate the total value of all scores
##find the average score of the population
##print the total number of scores
##print the total value of all scores
##print the average of all of the scores
##while a sample has an average that is less than the
##average of all scores add a random value 1000 - 1600
##to the sample until the average is no longer less than
##the average of all scores
##please note: this could result in lots of numbers
##being appended to the sample
##print the population
##adjust the population by
##removing the highest and lowest scores from each sample
##print the (adjusted) population
##calculate the total number of (adjusted) scores
##calculate the total value of all (adjusted) scores
##find the average score of the (adjusted) population
##print the total number of (adjusted) scores
##print the total value of all (adjusted) scores
##print the average of all of the (adjusted) scores
Sample Output
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>>
RESTART: /Users/janetbrownsederberg/Stonehill/Stonehill_Fall_2020/CSC102A_Fall_2020/CSC102_Fall_2020_HomeworkSolutions_JBS/SAT_Analysis_While.py
Population is:
[[1241, 1398, 562, 1247, 1465, 1525, 1328, 825, 1161, 1418], [820, 614, 1299, 1304, 595, 938, 1297], [856, 772, 768, 1396, 625, 559], [975, 883, 1568, 704, 1588, 1485], [1025, 1424, 971, 499, 698, 671]]
Number of scores counted is:
35
Total value of all scores counted is:
36504
Average of all scores is:
1042.9714285714285
Adjusted population is:
[[1241, 1398, 562, 1247, 1465, 1525, 1328, 825, 1161, 1418], [820, 614, 1299, 1304, 595, 938, 1297, 1569], [856, 772, 768, 1396, 625, 559, 1159, 1305, 1152, 1311, 1098, 1336, 1048, 1000, 1547], [975, 883, 1568, 704, 1588, 1485], [1025, 1424, 971, 499, 698, 671, 1511, 1026, 1100, 1510]]
After removal of max an min values the population is:
[[1241, 1398, 1247, 1465, 1328, 825, 1161, 1418], [820, 614, 1299, 1304, 938, 1297], [856, 772, 768, 1396, 625, 1159, 1305, 1152, 1311, 1098, 1336, 1048, 1000], [975, 883, 1568, 1485], [1025, 1424, 971, 698, 671, 1026, 1100, 1510]]
Adjusted number of scores counted is:
39
Adjusted total value of all scores counted is:
43517
Adjusted average of all scores is:
1115.820512820513
>>>
Done in Python Format please. Other codes provided for this question on here were not correct
import random
population=[]
for i in range(5):
sample=[]
n=random.randint(5,10)
print n
for num in range(n):
sample.append(random.randrange(400,1600))
population.append(sample)
print "population is:",population
print "total number of scores:",len(population)
def sum(lst):
total = 0
for element in lst:
if (type(element) == type([])):
total = total + sum(element)
else:
total = total + element
return total
tot=sum(population)
print "Sum of all scores:",tot
avg=tot//len(population)
print "average of all scores:",avg
print "sample list is:",sample
sam_tot=sum(sample)
print "sample Sum is:",sam_tot
sam_avg=sam_tot//len(sample)
print "sample average:",sam_avg
while(sam_avg<avg):
sample.append(random.randrange(1000,1600))
sam_avg=sam_tot//len(sample)
print sample
def nested_remove(L, x):
if x in L:
L.remove(x)
else:
for element in L:
if type(element) is list:
nested_remove(element, x)
for i in range(5):
a=max(population[i])
nested_remove(population,a)
b=min(population[i])
nested_remove(population,b)
print "after remove min,max in each sample:",population
tot=sum(population)
print "Sum of all scores:",tot
avg=tot//len(population)
print "average of all scores:",avg
Hope this helpful
Kindly upvote please it will help ma alot and please dont
downvote
THANK YOU IN ADVANCE