Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 format() and a couple other things but I can't get them to work.

EDIT: I use only even integers.

like image 665
Dan G. Avatar asked Jan 25 '26 12:01

Dan G.


1 Answers

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
like image 55
mgilson Avatar answered Jan 28 '26 01:01

mgilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!