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

  • Home
  • SEARCH
  • 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 9229307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:32:21+00:00 2026-06-18T05:32:21+00:00

I keep getting a TypeError: unsupported operand type for +: ‘int’ and ‘list’ so

  • 0

I keep getting a TypeError: unsupported operand type for +: ‘int’ and ‘list’
so I guess the array isn’t being indexed? Please assist.

def main():
    arr = [1, 2, 3, 4, 5]
    length = len(arr)
    maxAns = msa2(length, arr)
    print maxAns

def msa2(length, *arr):
    maxThus = 0
    for i in range(0, length):
        sum = 0
        for j in range(i, length):
            sum = sum + arr[j]     # how to get value in index j
            max(maxThus, sum)
    return maxThus

if __name__ == '__main__':
    main()
  • 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-18T05:32:22+00:00Added an answer on June 18, 2026 at 5:32 am

    You should not use *arr; remove the * wildcard character and your code will work.

    With the wildcard character, the argument passed into msa2 is seen as one of potentially more extra positional arguments, so arr inside msa2 is a list of those arguments, with the first element being the list you passed in when you called msa2:

    >>> def foo(*args):
    ...     print args
    ... 
    >>> foo(1, 2, 3)
    (1, 2, 3)
    >>> foo([1, 2, 3])
    ([1, 2, 3],)
    

    Your function also will always return 0; you do not update maxThus anywhere. You probably meant to assign the result of max(maxThus, sum) to maxThus:

    maxThus = max(maxThus, sum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i use slice to remove the first array I keep getting. TypeError: data.slice
I keep getting this error: TypeError: Error #1006: setSize is not a function. at
I keep getting the TypeError: Error #1010 when trying to create the constructor code
I keep getting this error when I try to load my templates: TypeError: cannot
I keep getting this error Uncaught TypeError: Cannot read property 'LatLng' of undefined when
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I keep getting this error and have no idea why. I googled and scanned
I keep getting this error on emulator: I copied this from a tutorial and

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.