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:
List starts at 5 The formula I use = last number in a list X 2 The new entry to the list is 10 The next new entry is 20
My non-working code is below:
mean = 198 standard_deviation = 85 list = [((mean)-(standard_deviation*3))] list.append(((list[-1])+(standard_deviation*.1))) print(list) [-55.930192782739596, -47.4592697321513]
I’d like to be able to tell the array to stop after 30 entries.
Advertisement
Answer
list = [((mean)-(std*3))] for n in range(60): list.append(((list[-1])+(std*.1)))