(Aug-23-2021, 02:44 PM)ibreeden Wrote:(Aug-23-2021, 02:10 PM)Mark17 Wrote: Why is the if block failing to keep negative integers out of the list?Because you are generating a new random price in the "else" block which can again be negative.
Apparently you mean to do this:
price_chg = np.arange(-10,11,2) stock_prices = [100] for i in range(10001): random_price = stock_prices.append(stock_prices[-1] + np.random.choice(price_chg)) if random_price < 0: stock_prices.append(0) else: stock_prices.append(random_price)
When will the "stupid mistakes" end? Rhetorical question. :)
Thank you!