Add Mad
This commit is contained in:
parent
2d7c0250a5
commit
fd0df5dccd
15
main.py
15
main.py
|
|
@ -45,7 +45,6 @@ def get_median():
|
||||||
sorted_state = state
|
sorted_state = state
|
||||||
sorted_state.sort()
|
sorted_state.sort()
|
||||||
n = len(sorted_state)
|
n = len(sorted_state)
|
||||||
median = 0
|
|
||||||
if n % 2 == 0:
|
if n % 2 == 0:
|
||||||
median = (sorted_state[n // 2 - 1] + sorted_state[n // 2]) / 2
|
median = (sorted_state[n // 2 - 1] + sorted_state[n // 2]) / 2
|
||||||
else:
|
else:
|
||||||
|
|
@ -112,6 +111,14 @@ def get_population_standard_deviation():
|
||||||
return std_dev
|
return std_dev
|
||||||
|
|
||||||
|
|
||||||
|
def get_mean_average_deviation():
|
||||||
|
global state
|
||||||
|
mean = get_mean()
|
||||||
|
n = len(state)
|
||||||
|
mad = sum(abs(x - mean) for x in state) / n
|
||||||
|
return mad
|
||||||
|
|
||||||
|
|
||||||
def start_shell():
|
def start_shell():
|
||||||
global state
|
global state
|
||||||
state = []
|
state = []
|
||||||
|
|
@ -149,8 +156,10 @@ def handle_input():
|
||||||
case 'pvariance':
|
case 'pvariance':
|
||||||
print(get_population_variance())
|
print(get_population_variance())
|
||||||
case 'iqr':
|
case 'iqr':
|
||||||
lower, upper, range = get_iqr()
|
lower, upper, iqr = get_iqr()
|
||||||
print(f"Lower: {lower} - Upper: {upper} - Range: {range}")
|
print(f"Lower: {lower} - Upper: {upper} - Range: {iqr}")
|
||||||
|
case 'mad':
|
||||||
|
print(get_mean_average_deviation())
|
||||||
case 'print':
|
case 'print':
|
||||||
if state is not None:
|
if state is not None:
|
||||||
print(f"{state}")
|
print(f"{state}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue