# import statistics library as stat
#
import statistics as stat
#
# import matplotlib.pyplot as plt and NumPy as np
import matplotlib.pyplot as plt
import numpy as np
temps = [45, 51, 38, 42, 47, 51, 52, 55, 48, 43]
n = len(temps)
# for plotting purposes I have added an array of days from 1 to 10
days = np.linspace(1,n,n)
print ('%.3f'%stat.mean (temps))
print ('%.3f'%stat.median (temps))
print (stat.mode (temps))
print ('%.3f'%stat.variance (temps))
print ('%.3f'%stat.stdev (temps))
47.200
47.500
51
27.511
5.245
# Plot the temperatures vs the days as a scatter plot using a red "x"
plt.plot (temps, 'rx')
plt.plot (days, 'rx')
#
# Plot the mean as a horizontal line in green
mean = stat.mean (temps)
x = np.linspace(1, n, n)
y = np.ones( len(x) ) * mean
plt.plot (y, 'g')
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
std = stat.stdev (temps)
plt.plot (std, '--b')
plt.show()
import random
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
print (random.randint(100, 200))
189
187
116
184
127
104
135
125
168
101
153
177
185
136
101
x = np.random.uniform(size = 15)
print (x)
[0.63945179 0.22633064 0.92766036 0.10756087 0.44549528 0.87086742
0.43296678 0.63096421 0.69546942 0.30713326 0.1518107 0.56652892
0.06799208 0.94159958 0.58739985]
x= np.random.randint ( low = 10, high = 40, size = 15)
print (x)
[38 27 34 35 21 21 21 28 38 39 11 28 25 18 23]
x = np.random.normal(size = 15)
print (x)
[-1.40412794 -0.33124109 -1.44853356 -0.84485997 0.32842116 0.57450855
-1.49263955 1.42220168 -0.81637463 1.24479916 -2.37556885 0.07273198
1.4736412 0.33908039 0.6317623 ]
x = np.random.normal(size = 15)
x = 20 + (0.5) * x
print (x)
[20.22953584 20.60095101 19.49181117 19.40841444 19.41291037 19.69064791
19.77108411 20.45844252 19.60228026 20.14583875 20.11163825 19.73212068
20.43418853 20.15624338 19.65308862]