0

I am trying to solve a problem using python. In which I have to deal with large integers (upto 500 digits). According to my current stage of understanding, python can handle any numbers in same traditional way. But I have problem in simple addition like this:

>>> p= 1001101111101011011100101100100110111011111011000100111100111110111101011011011100111001100011111010
>>> q= 0011111011111010111101111110101101111001111111100011111101101100100011010011111011111110110011111000
>>> p+q
1001101111105557844987142979708366943425581971579987152809865568761000527613931421735161949470823522L

Can anyone please explain why i got such an error.

Abhishek Kashyap
  • 3,332
  • 2
  • 18
  • 20
  • The result should just have 0s, 1s, and 2s. – Charlie Haley Aug 27 '15 at 20:51
  • 1
    [I've closed this as a duplicate of a question explaining what the 0 prefix means; if instead you're puzzled by something else, please edit to clarify and we can reopen.] – DSM Aug 27 '15 at 20:52
  • @DSM and as you probably already know, in Python 3 a leading zero is a syntax error so nobody gets surprised by this again. It's too bad that this conflicts with the intuitive understanding that leading zeros aren't significant. – Mark Ransom Aug 27 '15 at 20:55
  • P.S. it has nothing to do with large integers, you can see the problem with `100+010`. – Mark Ransom Aug 27 '15 at 20:56
  • No [DSM](http://stackoverflow.com/users/487339/dsm) I am pretty clear now. I am new in python as well as in Stack Exchange. So, that's my fault. I am sorry. – Abhishek Kashyap Sep 30 '15 at 06:15
  • @[Mark Ransom](http://stackoverflow.com/users/5987/mark-ransom), No Sir, I don't use python 3. I didn't know the solution, I didn't know that the problem is due to the zero in the beginning, so, I thought this problem was somehow related to large Integers. Anyway, thanks for your attention. – Abhishek Kashyap Sep 30 '15 at 06:29

1 Answers1

2

Var q starts with a zero, making it an octal number, rather than decimal

AndrewGrant
  • 786
  • 7
  • 17