I’m attempting to build an array from a known starting value that appends to itself based on a formula that includes the last number of the list. I’d like to do this a specified number of times. So for example:
JavaScript
x
5
1
List starts at 5
2
The formula I use = last number in a list X 2
3
The new entry to the list is 10
4
The next new entry is 20
5
My non-working code is below:
JavaScript
1
9
1
mean = 198
2
standard_deviation = 85
3
4
list = [((mean)-(standard_deviation*3))]
5
list.append(((list[-1])+(standard_deviation*.1)))
6
print(list)
7
8
[-55.930192782739596, -47.4592697321513]
9
I’d like to be able to tell the array to stop after 30 entries.
Advertisement
Answer
JavaScript
1
4
1
list = [((mean)-(std*3))]
2
for n in range(60):
3
list.append(((list[-1])+(std*.1)))
4