Dan G. Dan G. - 1 year ago 67
Python Question

How do I force Python to keep an integer out of scientific notation

I am trying to write a method in Python 3.2 that encrypts a phrase and then decrypts it. The problem is that the numbers are so big that when Python does math with them it immediately converts it into scientific notation. Since my code requires all the numbers to function scientific notation, this is not useful.

What I have is:

coded = ((eval(input(':'))+1213633288469888484)/2)+1042

Basically, I just get a number from the user and do some math to it.

I have tried
and a couple other things but I can't get them to work.

EDIT: I use only even integers.

Answer Source

In python3, '/' does real division (e.g. floating point). To get integer division, you need to use //. In other words 100/2 yields 50.0 (float) whereas 100//2 yields 50 (integer)

Your code probably needs to be changed as:

coded = ((eval(input(':'))+1213633288469888484)//2)+1042

As a cautionary tale however, you may want to consider using int instead of eval:

coded = ((int(input(':'))+1213633288469888484)//2)+1042