r/pythonhelp • u/stonk_daddy • Oct 25 '20
Simple Variable Defining Question
How can I input variable CF properly into total_cashflows to yield
[-40000, 5000, 8000, 12000, 30000].
Code:
import numpy as np
rate = .08
Initial_investment = -40000
CF = [5000, 8000, 12000, 30000]
total_cashflows = [int(Initial_investment), int(CF)]
np.npv(rate, total_cashflows).round(5)
3
Upvotes
3
u/SnooRobots3248 Oct 26 '20
Since you want it at the beginning of the list that you have defined you will need to put the following code
CF.insert(0, Initial_investment)
print(CF) should give you [-40000, 5000, 8000, 12000, 30000]
however your last line of code isn't correct because you can't do this operation on a list. Even if you convert it into a int. consider revising