-
Notifications
You must be signed in to change notification settings - Fork 0
/
m3.py
33 lines (26 loc) · 1002 Bytes
/
m3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Finds the rate of change between each data point in _data array and returns
# an array of the calculated rates
def roc(_data: list) -> list:
rates: list = []
for i in range(len(_data)):
if not len(_data) - 1 <= i:
rates.append(_data[i + 1] / _data[i])
return rates
# Calculates the average rate of change for a list of rates _data and returns it
def avg_roc(_data: list) -> float:
average = 0.0
for value in _data:
average += value
average /= len(_data) - 1
return average
def predict(_data: list, _average: float, _start: int, _years: int) -> list:
data = [_data[_start] *1000]
for i in range(_years):
data.append((data[0] * (_average ** i + 1 + _start))*1000)
return data
# change populations to be percentages based of population of country
def scale(_data: list, _population: int) -> list:
data = []
for i in range(len(_data)):
data.append(((_data[i] * 1000) / _population) * 100)
return data