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 9305075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:50:58+00:00 2026-06-18T23:50:58+00:00

Why do I get this error? a[k] = q % b TypeError: ‘int’ object

  • 0

Why do I get this error?

    a[k] = q % b
 TypeError: 'int' object does not support item assignment

Code:

def algorithmone(n,b,a):
     assert(b > 1)
     q = n
     k = 0
     while q != 0:
        a[k] = q % b
        q = q / b
        ++k

     return k

print (algorithmone(5,233,676))
print (algorithmone(11,233,676))
print (algorithmone(3,1001,94))
print (algorithmone(111,1201,121))
  • 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-18T23:50:59+00:00Added an answer on June 18, 2026 at 11:50 pm

    You’re passing an integer to your function as a. You then try to assign to it as: a[k] = ... but that doesn’t work since a is a scalar…

    It’s the same thing as if you had tried:

    50[42] = 7
    

    That statement doesn’t make much sense and python would yell at you the same way (presumably).

    Also, ++k isn’t doing what you think it does — it’s parsed as (+(+(k))) — i.e. the bytcode is just UNARY_POSITIVE twice. What you actually want is something like k += 1

    Finally, be careful with statements like:

    q = q / b
    

    The parenthesis you use with print imply that you want to use this on python3.x at some point. but, x/y behaves differently on python3.x than it does on python2.x. Looking at the algorithm, I’m guessing you want integer division (since you check q != 0 which would be hard to satisfy with floats). If that’s the case, you should consider using:

    q = q // b
    

    which performs integer division on both python2.x and python3.x.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error: TypeError: object.__init__() takes no parameters when running my code, I
In python I get this error: TypeError: 'int' object is unsubscriptable This happens at
I get this error: TypeError: unsupported operand type(s) for +=: 'int' and 'tuple' Line
I get this error TypeError at /debate/1/ get_context_data() takes exactly 2 arguments (1 given)
I get this error when I run the code below. I have normally used
When I run my script, I get this error message: Syntax error: TypeError: Cannot
I get the following error: TypeError: list indices must be integers, not str on
I get this error while accessing a php script: W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class
I get this error when i try to upload an image: OSError at /upload/
I get this error on my Ice Cream Sandwich (Android 4.0) device and emulator.

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.