Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:08:37+00:00 2026-06-03T17:08:37+00:00

I wrote a simple script to simulate customer lifetime value (LTV) based on average

  • 0

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.
enter image description here

EDIT2 —I figured out the solution thanks to the help below. There were three problems in total:

  1. I mistakenly assigned the same name to a variable and function (+1 @autopopulated for pointing that out)
  2. This line was extraneous “ltvYears = ltvYears + [ltv_loop]”
  3. This line should have used used “ltv_loop” for the second argument “ltv = ltv + [calculateltv(ARPU, ltv_loop, MARGIN)]”

+1 @DonCallisto and @RikPoggi for the help that on items 2 and 3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:08:38+00:00Added an answer on June 3, 2026 at 5:08 pm

    ltvYears is a tuple, it’s defined like

    ltvYears = ('f',[])
    

    so when it comes to this line:

    ltvYears = ltvYears + [ltv_loop]
    

    Python doesn’t know what to do, as your error clearly tells:

    “TypeError: can only concatenate tuple (not “list”) to tuple”

    Is not clear what the behave of that line should be, so it’s hard to suggest a solution.

    Maybe you just need to define ltvYears as a list and call the .append method.


    Edit

    Here the OP said:

    ltvYears = ('f',[]) I added the 'f' to indicate that the array is to contain floats. Before I did this I was getting an error about multiplying floats and ints.

    You don’t need to do that. Python is not C.

    Just do:

    ltvYears = []
    

    and later:

    ltvYears.append(ltv_loop)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple script trying to programmatically create a script from the onEdit
I wrote a simple script using python-daemon which prints to sys.stdout : #!/usr/bin/env python
I wrote a simple script that is intended to do hierarchical clustering on a
I wrote a simple regex-script in PHP: <?php $string = \section{Test 1} sdfgsdfg; $regex
I wrote a simple powershell script that checks the number of tickets in a
A couple of weeks ago, I wrote a simple Ruby script to test a
I wrote a very simple Perl script that contains the following line. my $q_it
I wrote simple script test echo hello #<-- inside test if I press one
I wrote a simple script to solve a logic puzzle, the type of puzzle
on my way to help a fellow I wrote a simple F-Script without even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.