Question

In: Computer Science

b) Assume that someone has collected a set of measurements and wants some statistical data about...

b) Assume that someone has collected a set of measurements and wants some statistical data about them. Write a program that asks a user for measurements and prints the average, the maximum, and minimum measurement. User should be allowed to enter as many measurements as they want, until entering a negative measurement. The negative measurement should not be processed, but is just used to indicate that the user has finished entering measurements. (Do not use a list to store the measurements) (Working in Python 3.7 (Spyder))

c) For numbers from 2 to 100 print a series of lines indicating which numbers are divisors of other numbers. For each, print out "X divides Y", where X<=Y, and both X and Y are between 2 and 100. First few lines will be 2 divides 2, 3 divides 3...etc (Working in Python 3.7)

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: If second part is not what you are looking for. Just let me know.

#code for first part

#initializing total, count to 0

total=0

count=0

#initializing max and min to None

max=None

min=None

n=0

#looping until n is not negative

while n>=0:

    #getting input

    n=float(input('Enter a measurement (or a negative value to quit): '))

    #checking if n is 0 or positive

    if n>=0:

        #adding to total, updating count

        total+=n

        count+=1

        #updating max if n is greater than max or max's value is not initialized yet

        if max==None or n>max:

            max=n

        # updating min if n is less than min or min's value is not initialized yet

        if min==None or n<min:

            min=n

#finding average if count is above 0

avg=0

if count>0:

    avg=total/count

#displaying average, max and min

print('Average value: ',avg)

print('Maximum: ',max)

print('Minimum: ',min)

#code for second part

#looping from i=2 to i=100

for i in range(2,100+1):

    #looping from j=i to j=100

    for j in range(i,100+1):

        #checking if i divides j evenly

        if j%i==0:

            #displaying i and j

            print('{} divides {}'.format(i,j))

#output 1

Enter a measurement (or a negative value to quit): 12
Enter a measurement (or a negative value to quit): 13
Enter a measurement (or a negative value to quit): 15
Enter a measurement (or a negative value to quit): 100
Enter a measurement (or a negative value to quit): 4
Enter a measurement (or a negative value to quit): 2.1
Enter a measurement (or a negative value to quit): 889
Enter a measurement (or a negative value to quit): 23
Enter a measurement (or a negative value to quit): 13
Enter a measurement (or a negative value to quit): 456
Enter a measurement (or a negative value to quit): 2
Enter a measurement (or a negative value to quit): 34
Enter a measurement (or a negative value to quit): -34
Average value: 130.25833333333333
Maximum: 889.0
Minimum: 2.0

#output 2 (partial)

2 divides 2

2 divides 4

2 divides 6

2 divides 8

2 divides 10

2 divides 12

2 divides 14

2 divides 16

2 divides 18

89 divides 89

90 divides 90

91 divides 91

92 divides 92

93 divides 93

94 divides 94

95 divides 95

96 divides 96

97 divides 97

98 divides 98

99 divides 99

100 divides 100


Related Solutions

The following are some of the data collected in one of the mensuration exercises. The measurements...
The following are some of the data collected in one of the mensuration exercises. The measurements are volumes in m3/ha for 24 different plots: Column 1 Column 2 736 1009 1560 1413 990 1528 924 1079 1042 1207 1360 1770 936 826 1618 1573 1221 1259 1033 1564 1288 896 555 1462 a) Assume that each column of data comes from a different forest type. Is it very likely to get a variance ratio S12/S22 as big as, or greater...
A financial analyst collected some data about a company, which has two sources of financing: debt...
A financial analyst collected some data about a company, which has two sources of financing: debt (25%) and equity (the rest). The firm's bonds yield 7%, and the company's tax rate is 35%. The risk-free rate is 1.50%, the market risk premium is 5%, and the stock's beta is 0.8. Find the company's WACC.
If data set A has a larger standard deviation than data set B, what would be...
If data set A has a larger standard deviation than data set B, what would be different about their distributions?
Here is a link to the data set collected by Dr. Hernandez. Her research team has...
Here is a link to the data set collected by Dr. Hernandez. Her research team has a data set of the weight of fishes caught from both the contaminated lake and the pristine lake. Assume both of these data sets have equal variance. Perform the correct statistical test and determine the P value to test Dr. Hernandez's hypothesis. Report your answer for P rounded to four decimal places. Use formulas, functions, and the data analysis tool pack in Excel to...
Here is a link to the data set collected by Dr. Hernandez. Her research team has...
Here is a link to the data set collected by Dr. Hernandez. Her research team has a data set of the weight of fishes caught from both the contaminated lake and the pristine lake. Assume both of these data sets have equal variance. 1.) Perform the correct statistical test and determine the P value to test Dr. Hernandez's hypothesis. Report your answer for P rounded to four decimal places. Fish Weight (g) Pristine Contaminated 45.3 79.3 56.8 96.8 79.6 84.6...
Here is a link to the data set collected by Dr. Hernandez. Her research team has...
Here is a link to the data set collected by Dr. Hernandez. Her research team has a data set of the weight of fishes caught from both the contaminated lake and the pristine lake. Assume both of these data sets have equal variance. Fish Weight (g) Pristine Contaminated 45.3 79.3 56.8 96.8 79.6 84.6 61.4 79.6 39.6 97.6 89.3 80.5 74.9 76.9 95.5 89.7 71.6 86.6 92 89.4 76.3 72.5 46.5 92.3 77.6 68.9 88.7 56.9 70.6 99.5 55.4 87.3...
Assume that a researcher wants to collect data to make inference about the hourly wage in...
Assume that a researcher wants to collect data to make inference about the hourly wage in New Paltz area. The hourly wage in New Paltz area also follows a normal distribution and the standard deviation is also $5. What will be the required sample size, if the researcher wants to achieve a desired margin of error at $1.00 at the significant level of 95%. What will be the required sample size, if the researcher wants to achieve a desired margin...
The StatCrunch data set for this question contains the data measurements described in Question 11. (H0...
The StatCrunch data set for this question contains the data measurements described in Question 11. (H0 : µ1 - µ2 ≤ 0 HA : µ1 - µ2 > 0) Assume that the two samples are dawn from independent, normally distributed populations that have different standard deviations. Use this data set and the results from Question 11 to calculate the p-value for the hypothesis test. Round your answer to three decimal places; add trailing zeros as needed. The p-value = [S90PValue]....
The data set airquality is one of R’s included data sets. It shows daily measurements of...
The data set airquality is one of R’s included data sets. It shows daily measurements of ozone concentration (Ozone), solar radiation (Solar.R), wind speed (Wind), and temperature (Temp) for 5 summer months in 1977 in New York City. Some of the observations are missing and are recorded as NA, meaning not available. View an overall summary of the variables in airquality with the command > summary(airquality) Ignore the summaries for Month and Day since those variables should be factors, not...
Assume that 18 subjects received one of three treatments and produced the data reported in Data Set B.
  Assume that 18 subjects received one of three treatments and produced the data reported in Data Set B. Conduct a one-way ANOVA to see if the means of the three treatments are different on a statistically significant level. Complete an ANOVA table reporting the relevant SS, df, MS, and Fs. Also remember to include your critical value and whether you would reject your null hypothesis. Data Set B Treatment 1 Treatment 2 Treatment 3 50 60 70 55 60...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT