I wrote a simple script to simulate the customer life cycle (LTV) value based on the average revenue per user (ARPU), margin and the number of customers remaining customers (ltvYears). Below is my script. It throws an error in this line "ltvYears = ltvYears + [ltv_loop]". The error message "TypeError: can only concatenate the tuple (and not the" list ") for the tuple." Can someone tell me what causes this? I suspect that the problem may be related to "ltvYears = ('f', [])", where I added type code to fix another error (multiplying float by int).
I am new to Python, so a beginner error is very likely 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 is a screenshot of my variables.
EDIT2 --- I understood the solution thanks to the help below. There were three problems in total:
- I mistakenly assigned the same variable and function name (+1 @autopopulated to indicate this)
- This line was an extraneous "ltvYears = ltvYears + [ltv_loop]"
- This line should use the used "ltv_loop" for the second argument "ltv = ltv + [calculateltv (ARPU, ltv_loop, MARGIN)]"
+1 @DonCallisto and @RikPoggi for help, which in paragraphs 2 and 3
source share