# 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)
temps_mean = stat.mean(temps)
temps_median = stat.median(temps)
temps_mode = stat.mode(temps)
temps_var = round(stat.variance(temps), 3)
temps_stdev = round(stat.stdev(temps), 3)
print(f"Mean: {temps_mean} Median: {temps_median} Mode: {temps_mode} \nVariation: {temps_var} Std.Deviation: {temps_stdev}")
Mean: 47.2 Median: 47.5 Mode: 51
Variation: 27.511 Std.Deviation: 5.245
# Plot the temperatures vs the days as a scatter plot using a red "x"
plt.plot(temps, 'rx')
#
# Plot the mean as a horizontal line in green
mean_line = np.linspace(temps_mean, temps_mean, n)
plt.plot(mean_line,'--g')
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
upper_stdev = np.linspace(temps_mean + temps_stdev, temps_mean + temps_stdev, n)
lower_stdev = np.linspace(temps_mean - temps_stdev, temps_mean - temps_stdev, n)
plt.plot(upper_stdev, '--b')
plt.plot(lower_stdev, '--b')
plt.show()
from numpy import random
intlist = []
for i in range (0, 15):
x = random.randint(100, 200)
intlist.append(x)
print(f"{intlist}")
[179, 126, 194, 157, 173, 160, 154, 186, 118, 116, 101, 121, 161, 181, 105]
floatlist = []
for i in range (0, 15):
x = random.rand()
floatlist.append(x)
print(f"{floatlist}")
[0.5889049144230346, 0.8444138775592401, 0.5019060951206481, 0.19130812696664778, 0.49241701666823734, 0.2589828279132077, 0.21235458136764995, 0.31795262270190017, 0.5448411566432778, 0.8763527182224086, 0.5347663320579845, 0.4575073499600275, 0.6369783422132415, 0.47827805571769977, 0.7265458061005601]
floatlist2 = []
for i in range (0, 15):
x = random.uniform(10, 40)
floatlist2.append(x)
print(f"{floatlist2}")
[35.117102873315446, 22.72162418503908, 13.898792536109564, 28.84572217772116, 31.949549331749306, 29.70011058821256, 21.86238682732697, 16.59315875763883, 38.43625586608586, 12.246747080593554, 23.46838429182398, 19.90609569024181, 31.94315525419252, 23.09714222398587, 17.84300428023682]
floatlist3 = []
for i in range (0, 15):
x = random.randn()
floatlist3.append(x)
print(f"{floatlist3}")
[0.1806279438270327, 1.7006136753023011, -0.10983009922123653, -0.013268283134946152, 0.056107684410862106, 1.328334096174505, 0.9337488881528029, -1.4053184359444562, -0.12480933060960371, -1.7580134904206317, 1.2461358333428476, -0.16171434322510334, -1.2003434541070077, 1.5882703394603483, -1.0126047261088205]
floatlist4 = []
for i in range (0, 15):
x = random.normal(20, 0.5)
floatlist4.append(x)
print(f"{floatlist4}")
[19.985363691655813, 20.265672471374263, 19.930906702113337, 20.794987821532004, 20.367166356193888, 19.525753986131804, 19.914344814399303, 19.195751803700116, 20.2266772535403, 20.69433618441487, 20.353770723265825, 19.06949365327942, 19.93598478259912, 20.365452865139886, 20.619382122860774]