Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter a Googol in Python?

I've heard that Python does not have any upper limit with integers. So I wanted to give a try:

a = 1e100
b = 1
c = a + b + a
c - 2 * a
> 0.0

Unfortunately I realized that writing 1e2 returns a float while 100 returns an int.

I've then tested with long('1' + '0' * 100) which works.

a = long('1' + '0' * 100)
b = 1
c = a + b + a
c - 2 * a
> 1L

Is this solution the only way to affect a Googol to a variable?

Subsequent question:

How to avoid confusion between floating point and fixed point during computations?

like image 458
nowox Avatar asked May 03 '26 08:05

nowox


1 Answers

You can get a Googol like so:

10**100
like image 185
aaron_world_traveler Avatar answered May 05 '26 22:05

aaron_world_traveler



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!