I'm having a good deal of trouble figuring out how to sum the values of a list until they reach a specified goal. This is a H.W. assignment and it is as follows:
"Define a Python function threshold(dailyGains, goal) that behaves as follows. The first parameter is a list of integers that represent the daily gains in the value of a stock. The second paramter is a single positive number that is a profit goal. The function should return the minimum number of days for which the stock should be owned in order to achieve a profit that is equal to or greater than the stated goal. If the goal is unreachable, the function should return 0."
My own attempt is very muddled and I'm not usually so flummoxed. Sorry for any 'newbie' errors, but I could really appreciate some help:
###
goal = int(raw_input("Enter profit goal: "))
dailyGains = [3, 2, 4, 8, 5, 6, 9]
days = 0
profit = 0
newlist = []
def threshold(dailyGains, goal):
[x + x for x in dailyGains]
for x in dailyGains:
newlist.append(x + x)
print newlist
print threshold(dailyGains, goal)###