I wrote a simple script to simulate customer lifetime value (LTV) based on average revenue per user (ARPU), margin and the number of years customers remain customers (ltvYears). Below is my script. It throws an error at this line "ltvYears = ltvYears + [ltv_loop]". The error message is "TypeError: can only concatenate tuple (not "list") to tuple". Can someone tell me what is causing this? I suspect the problem may stem from "ltvYears = ('f',[])" where I added the type code to eliminate another error (multiplying float by int).
I'm new to Python so there's very likely a beginner mistake in this code.
lowYears = 0
highYears = 20
modeYears = 3
ARPU = 65.0*12.0
MARGIN = .30
ltvYears = ('f',[])
ltv = []
def ltv(arpu, years, margin):
return arpu * years * margin
N = 10000
for n in range(N):
#estimate LTV
ltv_loop = random.triangular(lowYears, highYears, modeYears)
ltvYears = ltvYears + [ltv_loop]
ltv = ltv + [ltv(ARPU, ltvYears, MARGIN)]
show = 0
if (show==1):
#plot ltv histogram
plt.hist(ltv,bins=10)
plt.title("LTV Probability Density")
plt.xlabel("")
plt.ylabel("$")
plt.show()
EDIT - Here is a screenshot of my variables.
EDIT2 ---I figured out the solution thanks to the help below. There were three problems in total:
+1 @DonCallisto and @RikPoggi for the help that on items 2 and 3
if ltvYears is a tuple then you can concat like so:
ltvYears += (ltv_loop,)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With