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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:07:08+00:00 2026-06-12T23:07:08+00:00

I try to write some code on Python2.7 , which will able to implement

  • 0

I try to write some code on Python2.7, which will able to implement a bignum arithmetic, using linear lists. I know, this is useless in Python, but it’s my homework in collage. I write some working pieces of code, but problem is in dividing. I’m sure that function works, but when I run code to test it, I just get wrong answer (in some cases). But if I execute code step-by-step, it works correctly.

I’m using linux, but I tested my code on my friend’s windows computer, and I got the same problem. I wrote code in Eclipse with PyDev, if it is matter.

My code on Ideone: Code

If lines in console output are the same – output is correct. On Ideone output is incorrect too. But if you put a breakpoint on line 383 and then go in the _simple_div method, answer will be correct

I hope you help me to find a reason of this.
P.S. Sorry for ugly code.

  • 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-12T23:07:09+00:00Added an answer on June 12, 2026 at 11:07 pm

    If I run your code, I get

    ~/coding:$ python divbug2.py 
    1-1
    10
    

    That -1 doesn’t look right. Is there a -1 being inserted somewhere in the division? First thing to try is to search for -1 in that function, which gives

            i-=1
            res._addFirst(i)
            if i==-1: i=0
    

    .. and that looks strange, because if i == -1, then you’ve just added it to res. Maybe we should check first, i.e.

            i-=1
            if i==-1: i=0
            res._addFirst(i)
    

    Swapping those two lines produces

    ~/coding:$ python divbug2.py 
    10
    10
    

    And then — after writing a real .copy() method, because copy.deepcopy was really slow and even using PyPy I got bored waiting for things to finish:

    >>>> all(int(str(LongNum(x)._simple_div(LongNum(y)))) == x/y for x in range(2000) for y in range(1, 2000))
    True
    

    I’m not sure why this was working for you when you did it step-by-step, but I’m a little surprised it worked at all.

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

Sidebar

Related Questions

I need to write a delegate function that can 'wrap' some while/try/catch code around
I am try to write some validation script using javascript and prototype. What I
I try to write a Facebook app. This app will communicate with a rfid
I am using Python to write a program that looks through lists of lists
I'm trying to make a simple TCP server using Twisted ,which can do some
So, I know some Python but I thought that I should try to add
I'm trying to write some unittests using trial for my twisted application, I wrote
I have some code like: try: do_the_first_part() except SomeError: do_the_next_part() I get an error
Hmm. I found this which seems promising: http://sourceforge.net/projects/mjpg-streamer/ Ok. I will try to explain
I recently stumbled across this article which describes how to code FizzBuzz using only

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.